QSystemTrayIcon does not disappear on MacOS
-
Hi! An OS-specific issue here (works fine on Windows) - I have an application which creates a QSystemTrayIcon and allows the users to interact with its context menu. One of the menu options is to close the program. On MacOS, I can click on the tray icon with a left-click or a right-click. The left-click brings up my application interface and shows the tray icon's context menu (on Windows the context menu is not shown in such case, which would be my preferred behavior) - selecting the close action properly closes the program and the icon disappears. However, when doing the same with a right-click, the interface is not shown (this is desired), the context menu appears, but selecting the close action leaves the tray icon visible and the program hangs in the Activity Monitor processes list. Is this a MacOS limitation?
A code sample:
void MyApp::setupTrayIcon() { // The m_trayIconMenu is a QMenu type object m_trayIconMenu.addActions({&m_closeApp}); m_trayIcon.setIcon(QIcon{":/myIcon.svg"}); m_trayIcon.setToolTip(applicationName()); m_trayIcon.setContextMenu(&m_context); m_trayIcon.show(); connect(&m_trayIcon, &QSystemTrayIcon::activated, &m_trayIcon, [this](QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) { // This brings up the application interface showApp(); } }); // m_closeApp is a QAction type object connect(&m_closeApp, &QAction::triggered, this, &QApplication::quit, Qt::QueuedConnection); }
-