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. QSystemTrayIcon does not disappear on MacOS
Forum Update on Monday, May 27th 2025

QSystemTrayIcon does not disappear on MacOS

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 508 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.
  • S Offline
    S Offline
    szumial
    wrote on last edited by
    #1

    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);
    }
    
    M 1 Reply Last reply
    0
    • S szumial

      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);
      }
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

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

      S 1 Reply Last reply
      0
      • M mpergand

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

        S Offline
        S Offline
        szumial
        wrote on last edited by
        #3

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

        M 1 Reply Last reply
        0
        • S szumial

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

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          @szumial
          You can attach the debugger to an external app, see https://doc.qt.io/qtcreator/creator-debugger-operating-modes.html#attach

          Can't help you more since I've never used this possibility.

          S 1 Reply Last reply
          0
          • M mpergand

            @szumial
            You can attach the debugger to an external app, see https://doc.qt.io/qtcreator/creator-debugger-operating-modes.html#attach

            Can't help you more since I've never used this possibility.

            S Offline
            S Offline
            szumial
            wrote on last edited by
            #5

            @mpergand Hey! Since there were no issues while debugging and I have migrated to Qt 6.5, I will mark this topic as solved, because the issue no longer exists after the migration. Thank you for the useful hints!

            1 Reply Last reply
            0
            • S szumial has marked this topic as solved on

            • Login

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