MacOS system tray issue
-
Hello people!
I have desktop app with main widget (QDialog) and system tray (QObject) with icon (QSystemTrayIcon) and context menu (QMenu). I have issue when I exit my app through system tray menu.
It has following pipeline:
QMenu.QAction::triggered -> SysTray::signalCloseApp -> MainWidget::slotProcessQuitRequest -> QMessageBox::exec (confirmed) -> MainWidget::signalCloseConfirmed -> AppInstance::slotCloseApp
AppInstance is inherited from QApplication.
Inside AppInstance::slotCloseApp I do some minor stuff and try to close my app by doing this code://some stuff code this->setQuitOnLastWindowClosed(true);//this line is only for mac this->closeAllWindows(); qApp->processEvents(QEventLoop::AllEvents); this->exit(0);
After doing this code all widgets are closed except system tray menu.
So when I am waiting my App to close, it is stuck until I click on system tray icon, only after that action app is fully exits with 0 return code. And system tray icon seems to be sort of "pushed" or "checked" until I click it again.
I don't have this issue on Windows 10, Ubuntu (arm and x86), Linux Mint, only on MacOS 14.1 (and 13 also).I tried to call AppInstance::slotCloseApp by emitting signal directly from MainWidget (by clicking test-purpose pushbutton), and App is closing without any issue (mainwidget and system tray close like in other OS). Also I can close my App without any issue by Ctrl+Q or clicking "Quit" in MacOS-dock context menu (not from system tray) . So I think it is only custom system tray issue.
When debugging I found that app is stuck inside some Cocoa code (qcocoaapplication.mm) forever till I click on systray icon.
I use Qt6.6.2 and MacOS 14.1 Sonoma.
If any info is needed, I'll try to answer questions ASAP.2 years ago similar theme was started by @achak (https://forum.qt.io/topic/137635/desktop-systray-example-issue-on-mac), but no solution was found. Now this topic seems to be dead.
So, if someone has same or similar issue, could please give me some advice or solution. Any help is appreciated. Thank you in advance.
-
Hi and welcome to devnet,
Can you provide a minimal compilable example that shows this behavior ?
This will allows people to help you debug your issue in an easier fashion. -
So, I created project with similar behavior to my original project: https://github.com/a-oleshko/MacOSSysTray