Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Very simple application crashes under Linux 64 bit (Ubuntu 11.10 and 12.04)

Very simple application crashes under Linux 64 bit (Ubuntu 11.10 and 12.04)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dremon_nl
    wrote on last edited by
    #1

    The following very simple code crashes in release mode under Linux 64 bit (tested on 3 different PCs running Ubuntu 11.10 and 12.04, Qt version 4.7.4 and 4.8.0). When the QApplication instance is moved outside of the AppServer class then it does not crash:

    testapp.pro:
    @TEMPLATE = app
    TARGET = testapp
    CONFIG += release
    HEADERS += appserver.h
    SOURCES += main.cpp appserver.cpp
    @

    main.cpp:
    @#include "appserver.h"
    #include <QMessageBox>

    int main(int argc, char** argv)
    {
    AppServer app(argc, argv);
    QMessageBox::warning(NULL, "test", "test");

    return 0;
    }
    @

    appserver.h:
    @#ifndef APPSERVER_H
    #define APPSERVER_H

    #include <QApplication>

    class AppServer
    {
    public:
    AppServer(int argc, char** argv);

    private:
    QApplication app_;
    };

    #endif // APPSERVER_H
    @

    appserver.cpp:
    @#include "appserver.h"

    AppServer::AppServer(int argc, char** argv)
    : app_(argc, argv)
    {
    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      I would guess it's probably crashing because the QApplication is private to AppServer, and as such, the QMessageBox (outside the scope of AppServer) has trouble has a problem with that.

      What's the reasoning of making QApplication a member of AppServer? If it really needs to be tightly coupled, you could perhaps subclass it, instead.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        First:
        The signature of the AppServer constructor is wrong. You must have an int reference:

        @
        AppServer(int &argc, char** argv);
        @

        It is stated in the docs.

        Second:
        Putting QApplication as private member into the class is nonsense. You can get a pointer to that instance always and everywhere by calling QApplication::instance().

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dremon_nl
          wrote on last edited by
          #4

          Thanks; the argc reference was indeed the case - missed it.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved