Flare Cat Flare Cat - 3 months ago 13
C++ Question

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

I'm making a console application on OS X that interacts with specific parts of the Desktop Environment (mainly the mouse using QCursor), so I cannot use a QCoreApplication (despite how much I want to).

The application works fine, it is just that it shows up in the dock whenever I run it from the command line. I looked at several other questions online, but none fixed the problem I'm having.

I looked into

QSystemTrayIcon
, and I would be fine with using it IF it would get rid of the pesky window that pops up. Here is my code narrowed down to a minimum that still has the problem I addressed above.

The .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();
}

Answer

A workaround would be doing it manually as describe here.

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.

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