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. MacOS system tray issue

MacOS system tray issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 498 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
    alex.olha
    wrote on last edited by
    #1

    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.
    sysTrayMenu.png

    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.
    sysTrayStuck.png
    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.
    cocoaCode.png

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      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
      • A Offline
        A Offline
        alex.olha
        wrote on last edited by
        #3

        Ok, already started to prepare example.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex.olha
          wrote on last edited by
          #4

          So, I created project with similar behavior to my original project: https://github.com/a-oleshko/MacOSSysTray

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon.xuan
            wrote on last edited by
            #5

            Hi, I have the same problem, have you solved it?

            1 Reply Last reply
            0

            • Login

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