Start a Qt tray process without dock icon on Mac

梦想的初衷 提交于 2019-12-12 19:19:50

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/49053792/start-a-qt-tray-process-without-dock-icon-on-mac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!