PDA

View Full Version : Extending QApplication: Debug crashes, Release works



LinuCC
30th October 2014, 14:51
Hi there!

I have a program using Qt-Widgets and Qt5 that is crashing when running it in Debug-mode, but works in Release (Both with QtCreator and "qmake && make debug").
Compiling on (Arch) Linux with Qt5.3 and GNU GCC 4.9.1.

Basically, I extend QApplication to initialize the Gui, which in this case is just a subclassed QMainWindow.

Interesting to note is that this will only happen if I use both "setApplicationName()" and "setApplicationVersion()". Using one or none of them works fine.
Additionally, if I show a QMainWindow directly without subclassing it (here done with WindowA) it works fine as well.

Here is the basic code:

ExtendingApp.h:


#include <QApplication>
#include <QtWidgets/QMainWindow>

class WindowA : public QMainWindow
{
Q_OBJECT
};

class ExtendingApp : public QApplication
{
Q_OBJECT
public:
ExtendingApp(int argc, char* argv[]) : QApplication(argc, argv)
{
setApplicationName("cOOK!erGUI");
setApplicationVersion("0.01");
}
void showWinA()
{
winA = new WindowA();
winA->show();
}
private:
WindowA* winA;
};


main.cpp:


#include "ExtendingApp.h"

using namespace std;

int main(int argc, char* argv[])
{
ExtendingApp app(argc, argv);
app.showWinA();
return app.exec();
}


The crash happens in "winA->show()".
Here is the backtrace:


#0 0x00007ffff6677c9a in strlen () from /usr/lib/libc.so.6
#1 0x00007ffff714a481 in QCoreApplication::arguments() () from /usr/lib/libQt5Core.so.5
#2 0x00007fffed9ed17f in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
#3 0x00007fffed9ed493 in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
#4 0x00007fffed9fbb1b in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
#5 0x00007fffed9ecbd1 in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
#6 0x00007ffff5faa986 in QWindowPrivate::create(bool) () from /usr/lib/libQt5Gui.so.5
#7 0x00007ffff7724974 in QWidgetPrivate::create_sys(unsigned long long, bool, bool) () from /usr/lib/libQt5Widgets.so.5
#8 0x00007ffff76ff545 in QWidget::create(unsigned long long, bool, bool) () from /usr/lib/libQt5Widgets.so.5
#9 0x00007ffff7708a92 in QWidget::setVisible(bool) () from /usr/lib/libQt5Widgets.so.5
#10 0x0000000000402def in ExtendingApp::showWinA (this=0x7fffffffe8c0) at ExtendingApp.h:21
#11 0x0000000000402b57 in main (argc=1, argv=0x7fffffffe9d8) at main.cpp:8


And the project-file:


TEMPLATE = app
TARGET = cober-gui-crash-test
INCLUDEPATH += .
QT += widgets
QT += core
CONFIG += debug_and_release

# Input
HEADERS += ExtendingApp.h
SOURCES += main.cpp


I dont really know what to do from here.
I could just modify my code so that it works, but I really would like to understand what I did wrong here.

Thank you.

ars
30th October 2014, 21:13
Long time ago I had a similar problem. Looking at QApplication documentation you will find the following prototype:

QApplication(int &argc, char ** argv)
Note the reference for argc. Change your ExtendingApp CTOR to

ExtendingApp(int &argc, char **argv)

Best regards
ars

LinuCC
31st October 2014, 00:29
It solved the issue.
I already thought this was a problem with a pointer, but spend a whole day without finding anything.

Thank you very much ars!