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. hangs after deleteLater if aplication is run in Xfvb or with '-platform offscreen'

hangs after deleteLater if aplication is run in Xfvb or with '-platform offscreen'

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.1k Views 2 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.
  • J Offline
    J Offline
    Joachim W
    wrote on last edited by Joachim W
    #1

    My Qt5 application has a standard main program of the form

        QApplication app{argc, argv};
        new MyMainWindow; // inherits from QMainWindow
        return app.exec();
    

    Termination is triggered within MyMainWindow through a call of deleteLater().

    For functional testing under Gitlab-CI, the application shall be run without opening an actual X display. I found two ways to do so:
    (1) Pass the arguments -platform offscreen to QApplication;
    (2) Xvfb :1 -screen 0 1024x768x16 &> xvfb.log & followed by DISPLAY=:1.0 and export DISPLAY.

    Everything works fine until deleteLater is called. At this point, instead of terminating, the application hangs - at difference from the correct behavior when run with regular X display. What's wrong?

    jsulmJ 1 Reply Last reply
    0
    • J Joachim W

      My Qt5 application has a standard main program of the form

          QApplication app{argc, argv};
          new MyMainWindow; // inherits from QMainWindow
          return app.exec();
      

      Termination is triggered within MyMainWindow through a call of deleteLater().

      For functional testing under Gitlab-CI, the application shall be run without opening an actual X display. I found two ways to do so:
      (1) Pass the arguments -platform offscreen to QApplication;
      (2) Xvfb :1 -screen 0 1024x768x16 &> xvfb.log & followed by DISPLAY=:1.0 and export DISPLAY.

      Everything works fine until deleteLater is called. At this point, instead of terminating, the application hangs - at difference from the correct behavior when run with regular X display. What's wrong?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Joachim-W Why do you allocate MainWindow on the heap? Allocate it on the stack and there should not be any problem.
      If you for some reason still want to allocate it on the heap then do:

      QApplication app{argc, argv};
      MyMainWindow *w =  new MyMainWindow; // inherits from QMainWindow
      auto result = app.exec();
      delete w;
      return result;
      

      Do not use deleteLater on MainWindow.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Joachim-W Why do you allocate MainWindow on the heap? Allocate it on the stack and there should not be any problem.
        If you for some reason still want to allocate it on the heap then do:

        QApplication app{argc, argv};
        MyMainWindow *w =  new MyMainWindow; // inherits from QMainWindow
        auto result = app.exec();
        delete w;
        return result;
        

        Do not use deleteLater on MainWindow.

        J Offline
        J Offline
        Joachim W
        wrote on last edited by
        #3

        @jsulm Neither stack allocation nor an explicite delete w work for me. Somehow ~MyMainWindow is called from within app.exec(). Here the stack trace:

        ....
        #9  0x00007ffff78b9b29 in MainWin::~MainWin() (this=0x5171c0)
            at /G/sw/Steca/gui/mainwin.cpp:106
        #10 0x00007ffff6d591a0 in QObject::event(QEvent*) ()
            at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #11 0x00007ffff7aeaa1b in QWidget::event(QEvent*) ()
            at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #12 0x00007ffff7bf0de4 in QMainWindow::event(QEvent*) ()
            at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #13 0x00007ffff7aac4b1 in QApplicationPrivate::notify_helper(QObject*, QEvent*)
            () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        #14 0x00007ffff7ab3950 in QApplication::notify(QObject*, QEvent*) ()
            at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
        --Type <RET> for more, q to quit, c to continue without paging--c
        #15 0x00007ffff6d2f5a9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #16 0x00007ffff6d3259b in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #17 0x00007ffff6d81233 in  () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #18 0x00007ffff5636f2e in g_main_context_dispatch () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
        #19 0x00007ffff56371c8 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
        #20 0x00007ffff563725c in g_main_context_iteration () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
        #21 0x00007ffff6d80863 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #22 0x00007ffff2e403e1 in  () at /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
        #23 0x00007ffff6d2e27b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        #24 0x00007ffff6d36262 in QCoreApplication::exec() () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
        ....
        
        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          calling deleteLater() an any top level window seems superfluous to me. As @jsulm said, just create it on the main() stack and trust that the framework will handle accordingly.

          If I had to venture a guess, the behaviour U R seeing is that the window system is deleting the window BEFORE the object destructor is actually called, then the destructor freaks out becuase there is no longer a valid handle to the native window.

          If you meet the AI on the road, kill it.

          J 1 Reply Last reply
          1
          • Kent-DorfmanK Kent-Dorfman

            calling deleteLater() an any top level window seems superfluous to me. As @jsulm said, just create it on the main() stack and trust that the framework will handle accordingly.

            If I had to venture a guess, the behaviour U R seeing is that the window system is deleting the window BEFORE the object destructor is actually called, then the destructor freaks out becuase there is no longer a valid handle to the native window.

            J Offline
            J Offline
            Joachim W
            wrote on last edited by
            #5

            @Kent-Dorfman How then to quit the application? I have a "quit" trigger connected to ptrMyMainWindow->deleteLater().

            aha_1980A 1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              Most of the time Qt will handle quitting the app automatically when last window is closed.
              Default this is true
              https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

              J 1 Reply Last reply
              1
              • J Joachim W

                @Kent-Dorfman How then to quit the application? I have a "quit" trigger connected to ptrMyMainWindow->deleteLater().

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Joachim-W

                https://stackoverflow.com/questions/8026101/correct-way-to-quit-a-qt-program

                Qt has to stay free or it will die.

                1 Reply Last reply
                2
                • mrjjM mrjj

                  Hi
                  Most of the time Qt will handle quitting the app automatically when last window is closed.
                  Default this is true
                  https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

                  J Offline
                  J Offline
                  Joachim W
                  wrote on last edited by
                  #8
                  This post is deleted!
                  mrjjM 1 Reply Last reply
                  0
                  • J Joachim W

                    This post is deleted!

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Joachim-W
                    you can just call
                    close();
                    on it.
                    If last toplevel window, the application will also quit and clean up.

                    1 Reply Last reply
                    2

                    • Login

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