-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
5.1.0 , 5.1.1, 5.2.0, 5.2.1, 5.3.2, 5.4.2, 5.5.1, 5.6.0 RC
-
None
-
Tested using Ubuntu 15.10 with Gnome 3.16, KDE and Unity; Fedora 23 with Gnome 3.18
When using both a QSystemTrayIcon and a QtQuick.Window in the same app running under Gnome, then closing the window doesn't trigger QApplication::lastWindowClosed and therefore quitOnLastWindowClosed = true has no effect.
The issue does not occur if any of the following is the case:
- the tray icon is created but not shown
- the QtQuick.Window is replaced by a QMainWindow
- the app is run under KDE or Ubuntu's Unity
I could track it down to differences in the code sending lastWindowClosed for QWindow and QWidget based apps.
Why lastWindowClosed isn't sent when closing a QtQuick.Window
When closing a QtQuick.Window, QWindowPrivate::maybeQuitOnLastWindowClosed() is called (qtbase/src/gui/kernel/qwindow.cpp). When iterating over the windows, it finds two: the window that has been closed, and a window with the object name "QSystemTrayIconSysWindow". Because the latter is still visible, lastWindowClosed is not sent and the app keeps running.
Why lastWindowClosed is sent when closing a QMainWindow
When closing a QMainWindow, QWidgetPrivate::close_helper() is called (qtbase/src/widgets/kernel/qwidget.cpp). It iterates not over the windows but over the top-level widgets. This list contains the objects with the object names "QSystemTrayIconSys" and "MainWindow". The tray icon widget has Qt::WA_QuitOnClose disabled, so it isn't considered. The MainWindow is no longer visible and therefore also not considered. Thus, we have no more visible top-level widgets with Qt::WA_QuitOnClose, so lastWindowClosed is emitted.
Why KDE and Unity are not affected
On KDE or Ubuntu's Unity, lastWindowClosed is emitted even when a QtQuick.Window is closed because no QSystemTrayIconSysWindow exists in the list of windows.