MacOS application without menu bar: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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).
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}


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:
[[Category:HowTo]]


See Apple’s doc about [http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 <span class="caps">LSUIE</span>lement] ''[developer.apple.com]'' for more info.
Sometimes you want to create an application that runs in the background and should not have a menu bar or appear in the macOS Dock. There is no standard way in Qt itself to tell the application so (i.e. no setter on the QApplication object for example).


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:
Instead, one has to tell the macOS 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 the docs about [http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#qmake-info-plist <span class="caps">QMAKE</span>_INFO_PLIST] ''[doc.qt.nokia.com]'' for some more details.
<code>
<key>LSUIElement</key>
<string>1</string>
</code>
 
See Apple's doc about [http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 LSUIElement] 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:
 
<code>
QMAKE_INFO_PLIST = /path/to/your/custom/Info.plist
</code>
 
See the docs about [http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#qmake-info-plist QMAKE_INFO_PLIST] 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.
'''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.
Line 13: Line 26:
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:
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 @<span class="caps">ICON</span>@, @<span class="caps">TYPEINFO</span>@ and @<span class="caps">EXECUTABLE</span>@ placeholders as is, they are replaced with actual values by qmake/make once the Info.plist template is copied to your application bundle.
<code>
 
<?xml version="1.0" encoding="UTF-8"?>
Thanks to user [http://developer.qt.nokia.com/member/9132 paganotti] ''[developer.qt.nokia.com]'' who pointed out this solution in this [http://developer.qt.nokia.com/forums/viewthread/5104 forum thread] ''[developer.qt.nokia.com]''
<[[Image:DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
 
<plist version="0.9">
===Categories:===
<dict>
    <|]]— start of standard entries —>
<key>CFBundleIconFile</key>
<string>@ICON@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>Created by Qt/QMake</string>
<key>CFBundleSignature</key>
<string>@TYPEINFO@</string>
<key>CFBundleExecutable</key>
<string>@EXECUTABLE@</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.@EXECUTABLE@</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<!— start of customized entries —>
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>
</code>


* [[:Category:HowTo|HowTo]]
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.

Latest revision as of 21:59, 14 June 2016

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

Sometimes you want to create an application that runs in the background and should not have a menu bar or appear in the macOS 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 macOS 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:

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

See Apple's doc about LSUIElement 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:

QMAKE_INFO_PLIST = /path/to/your/custom/Info.plist

See the docs about QMAKE_INFO_PLIST 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:

<?xml version="1.0" encoding="UTF-8"?>
<[[Image:DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
    <|]] start of standard entries >
 <key>CFBundleIconFile</key>
 <string>@ICON@</string>
 <key>CFBundlePackageType</key>
 <string>APPL</string>
 <key>CFBundleGetInfoString</key>
 <string>Created by Qt/QMake</string>
 <key>CFBundleSignature</key>
 <string>@TYPEINFO@</string>
 <key>CFBundleExecutable</key>
 <string>@EXECUTABLE@</string>
 <key>CFBundleIdentifier</key>
 <string>com.yourcompany.@EXECUTABLE@</string>
 <key>NOTE</key>
 <string>This file was generated by Qt/QMake.</string>
 <! start of customized entries >
 <key>LSUIElement</key>
 <string>1</string>
</dict>
</plist>

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.