summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <[email protected]>2024-05-31 22:16:32 -0700
committerShawn Rutledge <[email protected]>2024-06-05 01:40:10 +0000
commit82cba0ca5c575d86accc02defd9c449e272ec1d0 (patch)
treed9bb811cc325a5e26bb7718a3d017b492b7120e4 /examples/widgets
parent8e4f1d9636bd9baf807b42e7c89453109e420b9c (diff)
systray example: if there is no system tray, allow waiting for one
Demonstrate that QSystemTrayIcon can wait for a tray to become available. For example QDBusTrayIcon::init() connects to QDBusServiceWatcher::serviceRegistered to detect the StatusNotifier service becoming available. So instead of unconditionally quitting if there is no tray, allow the user to choose to "Ignore" its absence, or "Close" the application. Realistically, applications in which a tray icon is an optional feature should not quit just because there's no tray. Task-number: QTBUG-94871 Change-Id: Ia8efd95fcfb9ff7c915ee8e259e9a0903fa7bcb3 Pick-to: 6.8 6.7 6.5 Reviewed-by: Axel Spoerl <[email protected]> Reviewed-by: Ilya Fedin <[email protected]> Reviewed-by: Dmitry Shachnev <[email protected]>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/desktop/systray/main.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/widgets/desktop/systray/main.cpp b/examples/widgets/desktop/systray/main.cpp
index d13bde11ceb..37f6809a331 100644
--- a/examples/widgets/desktop/systray/main.cpp
+++ b/examples/widgets/desktop/systray/main.cpp
@@ -13,10 +13,12 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
- QMessageBox::critical(nullptr, QObject::tr("Systray"),
- QObject::tr("I couldn't detect any system tray "
- "on this system."));
- return 1;
+ auto choice = QMessageBox::critical(nullptr, QObject::tr("Systray"),
+ QObject::tr("I couldn't detect any system tray on this system."),
+ QMessageBox::Close | QMessageBox::Ignore);
+ if (choice == QMessageBox::Close)
+ return 1;
+ // Otherwise "lurk": if a system tray is started later, the icon will appear.
}
QApplication::setQuitOnLastWindowClosed(false);