hangs after deleteLater if aplication is run in Xfvb or with '-platform offscreen'
-
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 ofdeleteLater()
.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
toQApplication
;
(2)Xvfb :1 -screen 0 1024x768x16 &> xvfb.log &
followed byDISPLAY=:1.0
andexport 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? -
@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.
-
@jsulm Neither stack allocation nor an explicite
delete w
work for me. Somehow~MyMainWindow
is called from withinapp.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 ....
-
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.
-
@Kent-Dorfman How then to quit the application? I have a "quit" trigger connected to
ptrMyMainWindow->deleteLater()
. -
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 -
-
@Joachim-W
you can just call
close();
on it.
If last toplevel window, the application will also quit and clean up.