Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Stop application from quitting when closing/destroying secondary widget
Wdowiak last edited by
Ok, so I have main window and settings window. The main window derives from QMainWindow whereas the settings one derives from QWidget.
The main window contains a tray icon and can be either visible or hidden. When I close the settings window while the main window is hidden, the entire application closes. How can I stop the application from quitting when I destroy the settings widget when main window is hidden?
By default main application event loop exits when last visible window is closed. You can disable that by setting QGuiApplication::setQuitOnLastWindowClosed to
Make sure to provide some other path to exit the event loop by calling QCoreApplication::exit() e.g. via option in the tray's menu or a menu action in the main window when it is visible, or your user won't be able to exit the app.
Wdowiak last edited by Wdowiak
Thank you, this solves the problem. As to alternative way to exit, I already have exit action on tray's menu.
Have a nice day.