Search code examples
c++macosqttray

Start a Qt tray process without dock icon on Mac


I have a bundle with a GUI, service and tray. Note they are three separate processes.

It may sound weird, the tray is a representation of the service and users can open the GUI which would create a tray if none exits.

So in my GUI code I have something like below:

QProcess::startDetached("my-tray");

The whole bundle is configured as the GUI is the main executable.

THE PROBLEM IS: when the GUI starts a tray, I can see two icons in dock. What I want is starting the tray without any extra icon in dock.

I have tried to set QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM to true as suggested here.

I have tried to change activation policy programmatically as suggested here.

I don't think set LSUIElement to 1 in plist file is a valid solution for me, because I still want the GUI show an icon in dock.

Currently, I put all processes in the MacOS folder within the bundle. Moving tray into Resources folder caused it failed to load some cocoa library.

This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "".

The whole project is a Qt project written in C++. The tray process is essentially a QSystemTrayIcon.


Solution

  • THE PROBLEM IS: when the GUI starts a tray, I can see two icons in dock.

    One possible solution would be to make the "tray" process its own application bundle (and still putting within the bundle of the main application) and setting

    <key>NSUIElement</key>
    <string>1</string>
    

    in the Info.plist of the tray bundle.