如何阻止 QApplication 出现在 Dock 中?

How can I stop a QApplication from showing up in the dock?

我正在 OS X 上制作一个控制台应用程序,它与桌面环境的特定部分(主要是使用 QCursor 的鼠标)交互,所以我不能使用 QCoreApplication(尽管我非常想要) .

该应用程序工作正常,只是每当我从命令行 运行 它时它就会出现在 Dock 中。我在网上查看了其他几个问题,但 none 解决了我遇到的问题。

我研究了 QSystemTrayIcon,如果它能摆脱弹出的讨厌的 window,我会很好地使用它。这是我的代码缩小到最低限度,但仍然存在我上面提到的问题。

.pro:

TARGET = project

QT += core
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT -= gui

CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app

SOURCES += main.cpp

main.cpp:

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QCursor cur;
    cur.setPos(0,0);

    return a.exec();
}

解决方法是按照此处所述手动执行此操作。

Luckily, if it is a cocoa application, you can hide the Dock icon yourself. To see if it is possible, right-click (Control-click) on the application icon. If "Show Package Contents" is in the menu that appears, you can hide the icon in the Dock.

If this is the case, select "Show Package Contents" and look for the "Info.plist" file inside the Contents folder. Open this file using TextEdit by right-clicking on it and choosing "Open With - Other" from the menu.

In the file, paste the following two lines just after on the 6th line:

<key>LSUIElement</key>
<string>1</string>

Save the file and close it. For the changes to take effect, you need to move the application to the desktop and them back to its original location (OS X keeps a cache of the file, so you need to trick it into checking it again).

Now when you open the application, no icon will appear in the Dock.

来源:http://www.macosxtips.co.uk/index_files/disable-the-dock-icon-for-any-application.php