Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Desktop-systray example issue on MAC

Desktop-systray example issue on MAC

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 6 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    achak
    wrote on 3 Jul 2022, 13:52 last edited by
    #1

    I try the https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/desktop/systray?h=6.3 on boyh Win and Mac platforms.
    On Win, close button closses the windows and removes its icon from the OS taskbar. But on the Mac the icon stills int the OS taskbar.
    How to fix the isuue on the Mac?

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mpergand
      wrote on 3 Jul 2022, 14:14 last edited by mpergand 7 Mar 2022, 14:14
      #2

      @achak said in Desktop-systray example issue on MAC:

      But on the Mac the icon stills int the OS taskbar.

      You didn't mention if the app did quit, as on mac , apps may not quit on last window closed.
      Maybe you need to set this property to true :
      setQuitOnLastWindowClosed(true)

      A 1 Reply Last reply 4 Jul 2022, 07:13
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 3 Jul 2022, 17:56 last edited by
        #3

        Hi,

        The behaviour of the example you link should be that the application does not quit when closing the main window. You should have a dialog telling you that it still lives and you can interact with it through the systray.

        Thus, the Windows behaviour would be wrong and the macOS correct.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 4 Jul 2022, 03:14
        0
        • S SGaist
          3 Jul 2022, 17:56

          Hi,

          The behaviour of the example you link should be that the application does not quit when closing the main window. You should have a dialog telling you that it still lives and you can interact with it through the systray.

          Thus, the Windows behaviour would be wrong and the macOS correct.

          A Offline
          A Offline
          achak
          wrote on 4 Jul 2022, 03:14 last edited by
          #4

          @SGaist On both Win and Mac the app did not quit.It just hides itself. ut on Win the app hides its icon at the taskbar and on Mac does not.

          1 Reply Last reply
          0
          • M mpergand
            3 Jul 2022, 14:14

            @achak said in Desktop-systray example issue on MAC:

            But on the Mac the icon stills int the OS taskbar.

            You didn't mention if the app did quit, as on mac , apps may not quit on last window closed.
            Maybe you need to set this property to true :
            setQuitOnLastWindowClosed(true)

            A Offline
            A Offline
            achak
            wrote on 4 Jul 2022, 07:13 last edited by achak 7 Apr 2022, 07:15
            #5

            @mpergand By the example, the app should not be closed. The app was hided and its icon at the OS taskbar had to be hided too. The app systray icon is visible.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 4 Jul 2022, 20:04 last edited by
              #6

              What you write is a bit confusing.

              So to clarify:

              1. both on Windows and macOS, the application continues to run.
              2. the systray icon appears properly on Windows
              3. the systray icon does not appear on macOS

              Do I get you correctly ?
              If so, which version of macOS ?
              On which type of machine ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 5 Jul 2022, 13:29 last edited by
                #7

                @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"

                1cd146bd-3b73-4e1c-b98d-45e26e8b0653-image.png


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alzix
                  wrote on 9 Jul 2022, 19:06 last edited by alzix 7 Sept 2022, 19:14
                  #8

                  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, the Window 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 the event inputs - see the log below.

                  I can see the QApplication is getting the Quit 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 and Application 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

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alzix
                    wrote on 13 Jul 2022, 18:27 last edited by
                    #9

                    any advice someone? this problem really blocks me :(
                    is there a way to forcibly terminate the application loop?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 17 Jul 2022, 16:20 last edited by
                      #10

                      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:

                      1. Start the application
                      2. Close the window using the red button
                      3. Quit the application from the systray icon

                      Second try:

                      1. Start the application
                      2. Close the window using the red button
                      3. Restore the window from the systray icon
                      4. Quit the application from the application menu

                      I can't reproduce your issue.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply 21 Jul 2022, 13:45
                      0
                      • S SGaist
                        17 Jul 2022, 16:20

                        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:

                        1. Start the application
                        2. Close the window using the red button
                        3. Quit the application from the systray icon

                        Second try:

                        1. Start the application
                        2. Close the window using the red button
                        3. Restore the window from the systray icon
                        4. Quit the application from the application menu

                        I can't reproduce your issue.

                        A Offline
                        A Offline
                        alzix
                        wrote on 21 Jul 2022, 13:45 last edited by
                        #11

                        @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;
                        }
                        
                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 21 Jul 2022, 18:37 last edited by
                          #12

                          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.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 1 Reply Last reply 21 Jul 2022, 18:52
                          1
                          • S SGaist
                            21 Jul 2022, 18:37

                            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.

                            A Offline
                            A Offline
                            alzix
                            wrote on 21 Jul 2022, 18:52 last edited by alzix
                            #13

                            @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 48a6b660-f356-41e4-9e7c-184316769465-image.png
                            If you need any additional logs i can provide.

                            is there another way to force close the exec loop?

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              alex.olha
                              wrote on 13 Mar 2024, 11:54 last edited by alex.olha
                              #14

                              @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.

                              1 Reply Last reply
                              0
                              • A alex.olha referenced this topic on 1 Jun 2024, 10:10

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved