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); }
-
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); }
-
@szumial
Hi,
Can't reproduce this.
Start your app in debug mode, when the app hangs, click Debug->Interrupt in QtCreator
and look where it hangs in the stack trace panel. -
@mpergand The problem is that it only happens when I launch my application when it is distributed with an installer. When I launch it from Qt Creator, I cannot reproduce it at all. Any other way to catch what could be going on?
-
@szumial
You can attach the debugger to an external app, see https://doc.qt.io/qtcreator/creator-debugger-operating-modes.html#attachCan't help you more since I've never used this possibility.
-