MacOS application without menu bar: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
[[Category:HowTo]]
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).
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:
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 [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.
<code><br />&lt;key&amp;gt;LSUIElement&amp;lt;/key&amp;gt;<br />&lt;string&amp;gt;1&amp;lt;/string&amp;gt;<br /></code>


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 Apple's doc about &quot;LSUIElement&amp;quot;:http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 for more info.


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.
If you edit this file manually it may be overwritten by the build system &amp;#40;at latest if you call &quot;make distclean&amp;quot;&amp;#41;. 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><br />QMAKE_INFO_PLIST = /path/to/your/custom/Info.plist<br /></code>
 
See the docs about &quot;QMAKE_INFO_PLIST&amp;quot;:http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#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 19:
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><br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;UTF-8&amp;quot;?&amp;gt;<br />&lt;[[Image:DOCTYPE plist SYSTEM &quot;file://localhost/System/Library/DTDs/PropertyList.dtd&quot;&gt;
 
&lt;plist version=&quot;0.9&quot;&gt;
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]''
&lt;dict&gt;
 
    &amp;lt;|]]— start of standard entries —&amp;gt;<br /> &lt;key&amp;gt;CFBundleIconFile&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;&amp;#x40;ICON&amp;amp;#x40;&lt;/string&amp;gt;<br /> &lt;key&amp;gt;CFBundlePackageType&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;APPL&amp;lt;/string&amp;gt;<br /> &lt;key&amp;gt;CFBundleGetInfoString&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;Created by Qt/QMake&amp;lt;/string&amp;gt;<br /> &lt;key&amp;gt;CFBundleSignature&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;&amp;#x40;TYPEINFO&amp;amp;#x40;&lt;/string&amp;gt;<br /> &lt;key&amp;gt;CFBundleExecutable&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;&amp;#x40;EXECUTABLE&amp;amp;#x40;&lt;/string&amp;gt;<br /> &lt;key&amp;gt;CFBundleIdentifier&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;com.yourcompany.&amp;#x40;EXECUTABLE&amp;amp;#x40;&lt;/string&amp;gt;<br /> &lt;key&amp;gt;NOTE&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;This file was generated by Qt/QMake.&lt;/string&amp;gt;<br /> &amp;lt;!— start of customized entries —&amp;gt;<br /> &lt;key&amp;gt;LSUIElement&amp;lt;/key&amp;gt;<br /> &lt;string&amp;gt;1&amp;lt;/string&amp;gt;<br />&lt;/dict&amp;gt;<br />&lt;/plist&amp;gt;<br /></code>
===Categories:===


* [[:Category:HowTo|HowTo]]
You can leave the &amp;#x40;ICON&amp;amp;#x40;, &amp;#x40;TYPEINFO&amp;amp;#x40; and &amp;#x40;EXECUTABLE&amp;amp;#x40; placeholders as is, they are replaced with actual values by qmake/make once the Info.plist template is copied to your application bundle.

Revision as of 09:38, 24 February 2015


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:

<br />&lt;key&amp;gt;LSUIElement&amp;lt;/key&amp;gt;<br />&lt;string&amp;gt;1&amp;lt;/string&amp;gt;<br />

See Apple's doc about "LSUIElement&quot;:http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 for more info.

If you edit this file manually it may be overwritten by the build system &#40;at latest if you call "make distclean&quot;&#41;. 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:

<br />QMAKE_INFO_PLIST = /path/to/your/custom/Info.plist<br />

See the docs about "QMAKE_INFO_PLIST&quot;:http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#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:

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

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