c++ - 如何阻止 QApplication 出现在 Dock 中?

标签 c++ qt command-line window qapplication

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

该应用程序运行良好,只是每当我从命令行运行它时它都会显示在停靠栏中。我在网上查看了其他几个问题,但没有一个解决了我遇到的问题。

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

.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

主要.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

关于c++ - 如何阻止 QApplication 出现在 Dock 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39261176/

相关文章:

c++ - Windows 上的 Qt 类错误

python - 如何指定某些命令行参数在 Python 中是必需的?

ubuntu - 使用 unix 命令重命名图像的名称

c++ - 根据函数定义进行函数声明

c++ - 停止使用 libpcap 捕获数据并将其保存在文件中

c++ - sockaddr_in 中的 sin_port

c++ - 删除链表中的节点

c++ - 如何在 QProcess 完成时销毁它并且类包含插槽

c++ - QTreeWidget选择点击版并双击

git - git diff 的奇怪输出到 Ubuntu 中的文件