Desktop-systray example issue on MAC
-
What you write is a bit confusing.
So to clarify:
- both on Windows and macOS, the application continues to run.
- the systray icon appears properly on Windows
- the systray icon does not appear on macOS
Do I get you correctly ?
If so, which version of macOS ?
On which type of machine ? -
@achak the docker/Menubar in windows and macOS may look similar, especially with win11 "new look", but they behave different.
For example, by default, the Mac Dock shows recent applications in the docks, but if there is no indicator dot under the icon, the app is not running.
If you don't want that, open the preferences of the dock und uncheck "Show recent applications in Dock"
-
i'm able to reproduce the issue on the
systray
example on MacOS 12.4 Monterey using 6.3.0 kit.After triggering the
Quit
action, theWindow
is closed, but the tray icon remains in highlighted mode (the background rect of the icon is highlighted) and does not disappear.Next click on the tray icon causes the application to exit the
exec()
loop and we reaching normal termination flow.I've added few debug prints and also subclassed
QApplication
for printing theevent
inputs - see the log below.I can see the
QApplication
is getting theQuit
event and is handling it (base class event function returns true) - but for some reason the application does not exit the event loop up until next click on systray.Is there any way to cause application to forcibly terminate the exec loop?
2022-07-09 21:48:10.764685+0300 systray[91693:28769015] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=91693 2022-07-09 21:48:10.764786+0300 systray[91693:28769015] SecTaskCopyDebugDescription: systray[91693]/0#-1 LF=0 2022-07-09 21:48:12.124082+0300 systray[91693:28769015] MyApp::event got QEvent::ApplicationActivate is_handled false 2022-07-09 21:48:12.124115+0300 systray[91693:28769015] MyApp::event got QEvent::ApplicationStateChange is_handled false 2022-07-09 21:48:13.895807+0300 systray[91693:28769015] MyApp::event got QEvent::ChildAdded is_handled true 2022-07-09 21:48:18.877474+0300 systray[91693:28769015] Quit action triggered 2022-07-09 21:48:18.877588+0300 systray[91693:28769015] Window::closeEvent 2022-07-09 21:48:18.877606+0300 systray[91693:28769015] Window::closeEvent accepted 2022-07-09 21:48:18.883353+0300 systray[91693:28769015] MyApp::event got QEvent::Quit is_handled true 2022-07-09 21:48:30.157394+0300 systray[91693:28769015] Application exit with retval 0
Notice the 12sec difference between
MyApp::event got QEvent::Quit
andApplication exit with retval 0
- the exit was triggered by an extra manual click on the tray icon.You can find my modified sources here: https://github.com/alzix/qtbase/tree/alzix/systray-debug/examples/widgets/desktop/systray
Tested on MacOs 12.4 (21F79) Monterey - Intel based MacBook Pro 16'' 2019
-
Can you give a detailed step by step set of instructions ?
Using your version with Qt 6.3.1 on macOS 12.4 I did not have any issue:
First try:
- Start the application
- Close the window using the red button
- Quit the application from the systray icon
Second try:
- Start the application
- Close the window using the red button
- Restore the window from the systray icon
- Quit the application from the application menu
I can't reproduce your issue.
-
@SGaist , not sure how can i attach a video recording here to prove my point - but this issue consistently reproduces both on this example and my other application. I tested on at least 5 different MacBooks.
But i think i have a brute brute force solution which does the trick:
i would like to use it only as last resort, though.bool MyApp::event(QEvent *ev) { bool is_handled = QApplication::event(ev); qDebug() << "MyApp::event got" << ev->type() << "is_handled" << is_handled << "is accepted" << ev->isAccepted(); if (ev->type() == QEvent::Quit) { std::exit(0); } return is_handled; }
-
That's why I requested these step by step procedures so I am sure I am doing things the same way as you.
By the way, std::exit does not allow for proper cleanup the way you use it.
-
@SGaist on both proposed scenarios the application does not quit automatically unless extra click on tray icon is made.
I noticed that the tray icon remains in kind of clicked state the background behind the icon remain highlighted
If you need any additional logs i can provide.is there another way to force close the exec loop?
-
@alzix @achak Hello guys! Did you find any solution for this problem? I have met same
problem on Qt6.6.2 and MacOS 14.1 Sonoma. When I exit my app from system tray menu (by calling qApp->exit(0)), I must click on main widget or system tray icon to fully exit app. But, when I call qApp->exit(0) from main widget -> app is exiting normally. Also app exits normally by clicking Quit in dock menu or by Ctrl+Q. Same code on Windows works as expected: app exits. -