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. Application crashes on exit after any interaction with QMenuBar
Qt 6.11 is out! See what's new in the release blog

Application crashes on exit after any interaction with QMenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
11 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    Please provide the stack trace you get when your application crashes. Otherwise it's pretty much Crystal Ball Debugging(tm)

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • W Offline
      W Offline
      WackyWormer
      wrote on last edited by
      #3

      I'm... not sure how to do that. Any advice for doing it on CLion would be helpful!

      1 Reply Last reply
      0
      • W Offline
        W Offline
        WackyWormer
        wrote on last edited by
        #4

        How's this?

        #0  0x00007ffff7e832c2 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
        #1  0x00007ffff7e7d743 in QXcbConnection::removeWindowEventListener(unsigned int) () from /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
        #2  0x00007ffff7e93d6a in QXcbWindow::destroy() () from /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
        #3  0x00007ffff7e93e98 in QXcbWindow::~QXcbWindow() () from /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
        #4  0x00007ffff7fe9ede in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/xcbglintegrations/libqxcb-glx-integration.so
        #5  0x00007ffff72fbe50 in QWindow::destroy() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
        #6  0x00007ffff78d8aba in QWidgetPrivate::deleteTLSysExtra() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #7  0x00007ffff78dbdd0 in QWidget::destroy(bool, bool) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #8  0x00007ffff78e3724 in QWidget::~QWidget() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #9  0x00007ffff7a24609 in QMenu::~QMenu() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #10 0x00007ffff6fdf28b in QObjectPrivate::deleteChildren() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #11 0x00007ffff78e3708 in QWidget::~QWidget() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #12 0x0000000000416cfe in MainWindow::~MainWindow() ()
        #13 0x00007ffff6403ff8 in __run_exit_handlers (status=0, listp=0x7ffff678e5f8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82
        #14 0x00007ffff6404045 in __GI_exit (status=<optimized out>) at exit.c:104
        #15 0x00007ffff63ea837 in __libc_start_main (main=0x414f76 <main>, argc=1, argv=0x7fffffffdcb8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdca8) at ../csu/libc-start.c:325
        #16 0x0000000000414ea9 in _start ()
        (gdb) 
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Read the documentation Luke :-)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            What version of Qt are you using ?
            What Linux distribution are you running ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • W Offline
              W Offline
              WackyWormer
              wrote on last edited by
              #7

              I saw that documentation, didn't help me copy/paste the stack trace through.

              I'm on Xubuntu 16.04, Qt 5.8.

              Source code isn't crazy large yet, my GitHub repo is https://github.com/cr01927/ROSIDE/tree/ROSProjectExplorerDev

              The menu stuff is in src/MainWindow.(h|cpp), the Slots classes are in src/Menus/(FileMenuSlots|EditMenuSlots.h|cpp)

              DiracsbracketD 1 Reply Last reply
              0
              • W WackyWormer

                I saw that documentation, didn't help me copy/paste the stack trace through.

                I'm on Xubuntu 16.04, Qt 5.8.

                Source code isn't crazy large yet, my GitHub repo is https://github.com/cr01927/ROSIDE/tree/ROSProjectExplorerDev

                The menu stuff is in src/MainWindow.(h|cpp), the Slots classes are in src/Menus/(FileMenuSlots|EditMenuSlots.h|cpp)

                DiracsbracketD Offline
                DiracsbracketD Offline
                Diracsbracket
                wrote on last edited by Diracsbracket
                #8

                @WackyWormer I found two problems when testing your program on my system:

                1. In your MainWindow constructor, you are using file_menu_ and edit_menu_ before they are actually assigned in InitMenuBar()...
                    file_menu_slots_ = new FileMenuSlots(file_menu_, this);
                    edit_menu_slots_ = new EditMenuSlots(edit_menu_, this);
                    InitMenuBar();
                
                void MainWindow::InitMenuBar() {
                    InitFileMenu();
                    InitEditMenu();
                   ...
                }
                
                void MainWindow::InitFileMenu() {
                    file_menu_ = menuBar()->addMenu(tr("&File"));
                ...
                }
                
                void MainWindow::InitEditMenu() {
                    edit_menu_ = menuBar()->addMenu(tr("&Edit"));
                ...
                }
                

                So, do this instead:

                void MainWindow::InitFileMenu() {
                    file_menu_ = menuBar()->addMenu(tr("&File"));
                    file_menu_slots_ = new FileMenuSlots(file_menu_, this);
                ...
                }
                
                void MainWindow::InitEditMenu() {
                    edit_menu_ = menuBar()->addMenu(tr("&Edit"));
                    edit_menu_slots_ = new EditMenuSlots(edit_menu_, this);
                ...
                }
                
                1. When using your get() technique in main() to keep the MainWindow constructor private, the app crashes on exit:
                   MainWindow::get();
                
                   return app.exec();
                

                Although it may work on Linux, it doesn't work as is on my Win10 system.
                So I tried to replace it by (it requires your MainWindow constructor to be public again and removing the show() statement in your constructor):

                    MainWindow w; // = MainWindow::get();
                    w.show();
                
                   return app.exec();
                

                With the above 2 changes, your program works and exits without crashing even after using the menu.

                1 Reply Last reply
                1
                • W Offline
                  W Offline
                  WackyWormer
                  wrote on last edited by
                  #9

                  Awesome, thanks! I really do want MainWindow to be a singleton class, so I need to figure out what I need to change for that to work.

                  DiracsbracketD 1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    WackyWormer
                    wrote on last edited by
                    #10

                    Nevermind, I changed my singleton implementation to return a pointer and its working now! Thanks!

                    1 Reply Last reply
                    0
                    • W WackyWormer

                      Awesome, thanks! I really do want MainWindow to be a singleton class, so I need to figure out what I need to change for that to work.

                      DiracsbracketD Offline
                      DiracsbracketD Offline
                      Diracsbracket
                      wrote on last edited by
                      #11

                      @WackyWormer said in Application crashes on exit after any interaction with QMenuBar:

                      I really do want MainWindow to be a singleton class

                      Have a look at this for a cross-platform solution:
                      https://stackoverflow.com/questions/5006547/qt-best-practice-for-a-single-instance-app-protection

                      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