Results 1 to 3 of 3

Thread: Extending QApplication: Debug crashes, Release works

  1. #1
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question Extending QApplication: Debug crashes, Release works

    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:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtWidgets/QMainWindow>
    3.  
    4. class WindowA : public QMainWindow
    5. {
    6. Q_OBJECT
    7. };
    8.  
    9. class ExtendingApp : public QApplication
    10. {
    11. Q_OBJECT
    12. public:
    13. ExtendingApp(int argc, char* argv[]) : QApplication(argc, argv)
    14. {
    15. setApplicationName("cOOK!erGUI");
    16. setApplicationVersion("0.01");
    17. }
    18. void showWinA()
    19. {
    20. winA = new WindowA();
    21. winA->show();
    22. }
    23. private:
    24. WindowA* winA;
    25. };
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include "ExtendingApp.h"
    2.  
    3. using namespace std;
    4.  
    5. int main(int argc, char* argv[])
    6. {
    7. ExtendingApp app(argc, argv);
    8. app.showWinA();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The crash happens in "winA->show()".
    Here is the backtrace:
    Qt Code:
    1. #0 0x00007ffff6677c9a in strlen () from /usr/lib/libc.so.6
    2. #1 0x00007ffff714a481 in QCoreApplication::arguments() () from /usr/lib/libQt5Core.so.5
    3. #2 0x00007fffed9ed17f in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
    4. #3 0x00007fffed9ed493 in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
    5. #4 0x00007fffed9fbb1b in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
    6. #5 0x00007fffed9ecbd1 in ?? () from /usr/lib/qt/plugins/platforms/libqxcb.so
    7. #6 0x00007ffff5faa986 in QWindowPrivate::create(bool) () from /usr/lib/libQt5Gui.so.5
    8. #7 0x00007ffff7724974 in QWidgetPrivate::create_sys(unsigned long long, bool, bool) () from /usr/lib/libQt5Widgets.so.5
    9. #8 0x00007ffff76ff545 in QWidget::create(unsigned long long, bool, bool) () from /usr/lib/libQt5Widgets.so.5
    10. #9 0x00007ffff7708a92 in QWidget::setVisible(bool) () from /usr/lib/libQt5Widgets.so.5
    11. #10 0x0000000000402def in ExtendingApp::showWinA (this=0x7fffffffe8c0) at ExtendingApp.h:21
    12. #11 0x0000000000402b57 in main (argc=1, argv=0x7fffffffe9d8) at main.cpp:8
    To copy to clipboard, switch view to plain text mode 

    And the project-file:
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = cober-gui-crash-test
    3. INCLUDEPATH += .
    4. QT += widgets
    5. QT += core
    6. CONFIG += debug_and_release
    7.  
    8. # Input
    9. HEADERS += ExtendingApp.h
    10. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by LinuCC; 30th October 2014 at 16:05. Reason: updated contents

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Extending QApplication: Debug crashes, Release works

    Long time ago I had a similar problem. Looking at QApplication documentation you will find the following prototype:
    Qt Code:
    1. QApplication(int &argc, char ** argv)
    To copy to clipboard, switch view to plain text mode 
    Note the reference for argc. Change your ExtendingApp CTOR to
    Qt Code:
    1. ExtendingApp(int &argc, char **argv)
    To copy to clipboard, switch view to plain text mode 

    Best regards
    ars

  3. The following user says thank you to ars for this useful post:

    LinuCC (31st October 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Thumbs up Re: Extending QApplication: Debug crashes, Release works

    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!

Similar Threads

  1. Replies: 4
    Last Post: 27th August 2013, 16:34
  2. QT 4.7.1 Win 7 x64 VS 2010: Debug works, Release crashes
    By new_voodoo in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2010, 20:14
  3. Program works in Release but not Debug
    By Ferric in forum Newbie
    Replies: 2
    Last Post: 28th January 2010, 02:08
  4. Release ok, debug crashes [compilable code]
    By Raccoon29 in forum Qt Programming
    Replies: 8
    Last Post: 16th December 2009, 16:48
  5. Replies: 3
    Last Post: 8th June 2009, 09:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.