MacOS application without menu bar

From Qt Wiki
Revision as of 16:15, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sometimes you want to create an application that runs in the background and should not have a menu bar or appear in the OS X dock. There is no standard way in Qt itself to tell the application so (i.e. no setter on the QApplication object for example).

Instead, one has to tell the OS X application launcher via the application bundle configuration in Info.plist. The file is located in YourFancyApplication.app/Contents/Info.plist. It is added to the bundle by Qt automatically and contains your application’s name and some other information which is filled in by qmake generated build steps. In order to remove the entire menu bar and dock functionality add to this file:

See Apple’s doc about LSUIElement [developer.apple.com] for more info.

If you edit this file manually it may be overwritten by the build system (at latest if you call “make distclean”). Fortunatelly, qmake provides a configuration option to point to a custom Info.plist file, which you can pre-modify with the above snippet. Just add to your .pro file:

See the docs about QMAKE_INFO_PLIST [doc.qt.nokia.com] for some more details.

Caveat: If you modify the Info.plist template, it is not automatically replaced in the bundle as of this writing (2011-10-10, Qt version 4.7.2)! To trigger this, you will have to remove the application bundle directory.

To start easy, just grab the default file from /path/to/your/qt/installation/mkspecs/default/Info.plist.app and add the snippet above. This looks like this then:

You can leave the @ICON@, @TYPEINFO@ and @EXECUTABLE@ placeholders as is, they are replaced with actual values by qmake/make once the Info.plist template is copied to your application bundle.

Thanks to user paganotti [developer.qt.nokia.com] who pointed out this solution in this forum thread [developer.qt.nokia.com]

Categories: