Important: Please read the Qt Code of Conduct -

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

  • 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:
    @TEMPLATE = app
    TARGET = testapp
    CONFIG += release
    HEADERS += appserver.h
    SOURCES += main.cpp appserver.cpp

    @#include "appserver.h"
    #include <QMessageBox>

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

    return 0;

    @#ifndef APPSERVER_H
    #define APPSERVER_H

    #include <QApplication>

    class AppServer
    AppServer(int argc, char** argv);

    QApplication app_;

    #endif // APPSERVER_H

    @#include "appserver.h"

    AppServer::AppServer(int argc, char** argv)
    : app_(argc, argv)

  • Moderators

    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.

  • 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.

    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().

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

Log in to reply