Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 5ab010e37991249ab4adaa24d6e39c6e > files > 27

qt5-qtdoc-5.1.1-2.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- deployment.qdoc -->
  <title>Deploying an Application on Mac OS X | QtDoc 5.1</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader"></div>
<div class="content">
<div class="line">
<div class="content mainContent">
<p class="naviNextPrevious headerNavi">
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#the-bundle">The Bundle</a></li>
<li class="level1"><a href="#static-linking">Static Linking</a></li>
<li class="level2"><a href="#building-qt-statically">Building Qt Statically</a></li>
<li class="level2"><a href="#linking-the-application-to-the-static-version-of-qt">Linking the Application to the Static Version of Qt</a></li>
<li class="level1"><a href="#frameworks">Frameworks</a></li>
<li class="level2"><a href="#building-qt-as-frameworks">Building Qt as Frameworks</a></li>
<li class="level2"><a href="#linking-the-application-to-qt-as-frameworks">Linking the Application to Qt as Frameworks</a></li>
<li class="level2"><a href="#creating-the-application-package">Creating the Application Package</a></li>
<li class="level1"><a href="#application-dependencies">Application Dependencies</a></li>
<li class="level2"><a href="#qt-plugins">Qt Plugins</a></li>
<li class="level2"><a href="#additional-libraries">Additional Libraries</a></li>
<li class="level2"><a href="#mac-os-x-version-dependencies">Mac OS X Version Dependencies</a></li>
<li class="level1"><a href="#the-mac-deployment-tool">The Mac Deployment Tool</a></li>
</ul>
</div>
<h1 class="title">Deploying an Application on Mac OS X</h1>
<span class="subtitle"></span>
<!-- $$$deployment-mac.html-description -->
<div class="descr"> <a name="details"></a>
<p>Beginning with Qt 4.5, a <a href="#macdeploy">deployment tool</a> is included that automates the procedures described here.</p>
<p>This document describes how to create a bundle and make sure that the application finds the resources it needs at run-time. We demonstrate the procedures in terms of deploying the Plug &amp; Paint example application that comes with the Qt installation package.</p>
<a name="the-bundle"></a>
<h2>The Bundle</h2>
<p>On Mac, a GUI application must be built and run from a bundle, which is a directory structure that appears as a single entity when viewed in the Finder. A bundle for an application typically contains the executable and all the resources it needs. Here is the snapshot of an application bundle structure:</p>
<p class="centerAlign"><img src="images/deployment-mac-bundlestructure.png" alt="" /></p><p>The bundle provides many advantages to the user:</p>
<ul>
<li>It is easily installable as it is identified as a single entity.</li>
<li>Information about a bundle is accessible from code.</li>
</ul>
<p>This is specific to Mac OS X and beyond the scope of this document. For more information about bundles, see <a href="http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/index.html">Apple's Developer Website</a>.</p>
<p>Add the following statement to your application's project file (<tt>.pro</tt>):</p>
<pre class="cpp">CONFIG-=app_bundle</pre>
<p>This tells <tt>qmake</tt> not to put the executable inside a bundle.</p>
<a name="static-linking"></a>
<h2>Static Linking</h2>
<p>If you want to keep things simple and have a few files to deploy, you must build your application with statically linked libraries.</p>
<a name="building-qt-statically"></a>
<h3>Building Qt Statically</h3>
<p>Start by installing a static version of the Qt library. Remember that you cannot use plugins and that you must build the dependent libraries such as image formats, SQL drivers, and so on with static linking.</p>
<pre class="cpp">cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span>
<span class="operator">.</span><span class="operator">/</span>configure <span class="operator">-</span><span class="keyword">static</span> <span class="operator">&lt;</span>other parameters<span class="operator">&gt;</span>
make sub<span class="operator">-</span>src</pre>
<p>You can check the various options that are available by running <tt>configure</tt> -help.</p>
<a name="linking-the-application-to-the-static-version-of-qt"></a>
<h3>Linking the Application to the Static Version of Qt</h3>
<p>Once Qt is built statically, the next step is to regenerate the makefile and rebuild the application. First, we must go into the directory that contains the application:</p>
<pre class="cpp">cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>examples<span class="operator">/</span>tools<span class="operator">/</span>plugandpaint</pre>
<p>Now run <tt>qmake</tt> to create a new makefile for the application, and do a clean build to create the statically linked executable:</p>
<pre class="cpp">make clean
qmake <span class="operator">-</span>config release
make</pre>
<p>You probably want to link against the release libraries, and you can specify this when invoking <tt>qmake</tt>. If you have Xcode Tools 1.5 or higher installed, you may want to take advantage of &quot;dead code stripping&quot; to reduce the size of your binary even more. You can do this by passing <tt>LIBS+= -dead_strip</tt> to <tt>qmake</tt> in addition to the <tt>-config release</tt> parameter.</p>
<p>Now, provided that everything compiled and linked without any errors, we should have a <tt>plugandpaint.app</tt> bundle ready for deployment. Try installing the bundle on a Mac OS x machine that does not have Qt or any Qt applications installed.</p>
<p>You can check what other libraries your application links to using the <tt>otool</tt>:</p>
<pre class="cpp">otool <span class="operator">-</span>L plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>MacOs<span class="operator">/</span>plugandpaint</pre>
<p>Here is what the output looks like for the statically linked Plug &amp; Paint:</p>
<pre class="cpp">plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>MacOS<span class="operator">/</span>plugandpaint:
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>Carbon<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>Carbon
        (compatibility version <span class="number">2.0.0</span><span class="operator">,</span> current version <span class="number">128.0.0</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>QuickTime<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>QuickTime
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">10.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libz<span class="operator">.</span><span class="number">1.dylib</span>
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.2.3</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>ApplicationServices<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>ApplicationServices
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">22.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libstdc<span class="operator">+</span><span class="operator">+</span><span class="operator">.</span><span class="number">6.dylib</span>
        (compatibility version <span class="number">7.0.0</span><span class="operator">,</span> current version <span class="number">7.3.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libgcc_s<span class="operator">.</span><span class="number">1.dylib</span>
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libmx<span class="operator">.</span>A<span class="operator">.</span>dylib
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">92.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libSystem<span class="operator">.</span>B<span class="operator">.</span>dylib
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">88.0.0</span>)</pre>
<p>If you see <i>Qt</i> libraries in the output, it probably means that you have both dynamic and static Qt libraries installed on your machine. The linker always chooses dynamic linking over static. If you want to use only static libraries, you can either:</p>
<ul>
<li>move your Qt dynamic libraries (<tt>.dylibs</tt>) away to another directory while you link the application and then move them back,</li>
<li>or edit the <tt>Makefile</tt> and replace link lines for the Qt libraries with the absolute path to the static libraries.</li>
</ul>
<p>For example, replace the following:</p>
<pre class="cpp"><span class="operator">-</span>lQtGui</pre>
<p>with this:</p>
<pre class="cpp"><span class="operator">/</span>where<span class="operator">/</span><span class="keyword">static</span><span class="operator">/</span>qt<span class="operator">/</span>lib<span class="operator">/</span>is<span class="operator">/</span>libQtGui<span class="operator">.</span>a</pre>
<p>The Plug &amp; Paint example consists of several components: The core application (Plug &amp; Paint), and the Basic Tools and Extra Filters plugins. As we cannot deploy plugins using the static linking approach, the bundle we have prepared so far is incomplete. The application will run, but the functionality will be disabled due to the missing plugins. To deploy plugin-based applications we should use the framework approach, which is specific to Mac OS x.</p>
<a name="frameworks"></a>
<h2>Frameworks</h2>
<p>In this approach, ensure that the Qt runtime is redistributed correctly with the application bundle, and that the plugins are installed in the correct location so that the application finds them.</p>
<p>There are two ways to distribute Qt with your application in the frameworks approach:</p>
<ul>
<li>Private framework within your application bundle.</li>
<li>Standard framework (alternatively use the Qt frameworks in the installed binary).</li>
</ul>
<p>The former is good if you have Qt built in a special way, or want to make sure the framework is there. It just comes down to where you place the Qt frameworks.</p>
<p>The latter option is good if you have many Qt applications and you want them use a single Qt framework rather than multiple versions of it.</p>
<a name="building-qt-as-frameworks"></a>
<h3>Building Qt as Frameworks</h3>
<p>We assume that you already have installed Qt as frameworks, which is the default when installing Qt, in the /path/to/Qt directory. For more information on how to build Qt, see the <a href="installation.html">Installation</a> documentation.</p>
<p>When installing, the identification name of the frameworks is set. This name is used by the dynamic linker (<tt>dyld</tt>) to find the libraries for your application.</p>
<a name="linking-the-application-to-qt-as-frameworks"></a>
<h3>Linking the Application to Qt as Frameworks</h3>
<p>After building Qt as frameworks, we can build the Plug &amp; Paint application. First, we must go to the directory that contains the application:</p>
<pre class="cpp">cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>examples<span class="operator">/</span>tools<span class="operator">/</span>plugandpaint</pre>
<p>Run <tt>qmake</tt> to create a new makefile for the application, and do a clean build to create the dynamically linked executable:</p>
<pre class="cpp">make clean
qmake <span class="operator">-</span>config release
make</pre>
<p>This builds the core application. Use the following to build the plugins:</p>
<pre class="cpp">cd <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>plugandpaintplugins
make clean
qmake <span class="operator">-</span>config release
make</pre>
<p>Now run the <tt>otool</tt> for the Qt frameworks, for example Qt Gui:</p>
<pre class="cpp">otool <span class="operator">-</span>L <span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span><span class="type">QtGui</span></pre>
<p>You would get the following output:</p>
<pre class="cpp"><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span><span class="type">QtGui</span>:
<span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        (compatibility version <span class="number">4.0.0</span><span class="operator">,</span> current version <span class="number">4.0.1</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>Carbon<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>Carbon
        (compatibility version <span class="number">2.0.0</span><span class="operator">,</span> current version <span class="number">128.0.0</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>QuickTime<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>QuickTime
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">10.0.0</span>)
<span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        (compatibility version <span class="number">4.0.0</span><span class="operator">,</span> current version <span class="number">4.0.1</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libz<span class="operator">.</span><span class="number">1.dylib</span>
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.2.3</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>ApplicationServices<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>ApplicationServices
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">22.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libstdc<span class="operator">+</span><span class="operator">+</span><span class="operator">.</span><span class="number">6.dylib</span>
        (compatibility version <span class="number">7.0.0</span><span class="operator">,</span> current version <span class="number">7.3.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libgcc_s<span class="operator">.</span><span class="number">1.dylib</span>
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libmx<span class="operator">.</span>A<span class="operator">.</span>dylib
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">92.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libSystem<span class="operator">.</span>B<span class="operator">.</span>dylib
        (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">88.0.0</span>)</pre>
<p>For the Qt frameworks, the first line (i.e&#x2e; <tt>path/to/Qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.0&#x2e;0, current version 4.0&#x2e;1)</tt>) becomes the framework's identification name which is used by the dynamic linker (<tt>dyld</tt>).</p>
<p>But when you are deploying the application, your users may not have the Qt frameworks installed in the specified location. For that reason, you must either provide the frameworks in an agreed location, or store the frameworks in the bundle. Regardless of which solution you choose, you must make sure that the frameworks return the proper identification name for themselves, and that the application looks for these names. Luckily we can control this with the <tt>install_name_tool</tt> command-line tool.</p>
<p>The <tt>install_name_tool</tt> works in two modes, <tt>-id</tt> and <tt>-change</tt>. The <tt>-id</tt> mode is for libraries and frameworks, and allows us to specify a new identification name. We use the <tt>-change</tt> mode to change the paths in the application.</p>
<p>Let's test this out by copying the Qt frameworks into the Plug &amp; Paint bundle. Looking at <tt>otool</tt>'s output for the bundle, we can see that we must copy both the QtCore and QtGui frameworks into the bundle. We will assume that we are in the directory where we built the bundle.</p>
<pre class="cpp">mkdir plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks
cp <span class="operator">-</span>R <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks
cp <span class="operator">-</span>R <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework
       plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks</pre>
<p>First we create a <tt>Frameworks</tt> directory inside the bundle. This follows the Mac OS X application convention. We then copy the frameworks into the new directory. As frameworks contain symbolic links, we use the <tt>-R</tt> option.</p>
<pre class="cpp">install_name_tool <span class="operator">-</span>id @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
       plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
install_name_tool <span class="operator">-</span>id @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
       plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span></pre>
<p>Then we run <tt>install_name_tool</tt> to set the identification names for the frameworks. The first argument after <tt>-id</tt> is the new name, and the second argument is the framework that we want to rename. The text <tt>@executable_path</tt> is a special <tt>dyld</tt> variable telling <tt>dyld</tt> to start looking where the executable is located. The new names specifies that these frameworks are located in the directory directly under the <tt>Frameworks</tt> directory.</p>
<pre class="cpp">install_name_tool <span class="operator">-</span>change path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>MacOs<span class="operator">/</span>plugandpaint
install_name_tool <span class="operator">-</span>change path<span class="operator">/</span>to<span class="operator">/</span>qt<span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>MacOs<span class="operator">/</span>plugandpaint</pre>
<p>Now, the dynamic linker knows where to look for QtCore and QtGui. We must ensure that the application also knows where to find the library, using <tt>install_name_tool</tt>'s <tt>-change</tt> mode. This basically comes down to string replacement, to match the identification names that we set earlier to the frameworks.</p>
<p>Finally, the QtGui framework depends on QtCore, so we must remember to change the reference for QtGui:</p>
<pre class="cpp">install_name_tool <span class="operator">-</span>change path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span></pre>
<p>After this, we run <tt>otool</tt> again and see that the application can find the libraries.</p>
<p>The plugins for the Plug &amp; Paint example makes it interesting. The basic steps we need to follow with plugins are:</p>
<ul>
<li>put the plugins inside the bundle,</li>
<li>run the <tt>install_name_tool</tt> to check whether the plugins are using the correct library,</li>
<li>and ensure that the application knows where to look for the plugins.</li>
</ul>
<p>We can put the plugins anywhere we want in the bundle, but the best location is to put them under Contents/Plugins. When we built the Plug &amp; Paint plugins, based on the <tt>DESTDIR</tt> variable in their <tt>.pro</tt> file, the plugins' <tt>.dylib</tt> files are in the <tt>plugins</tt> subdirectory under the <tt>plugandpaint</tt> directory. We just have to move this director.</p>
<pre class="cpp">mv plugins plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents</pre>
<p>For example, If we run <tt>otool</tt> on the Basic Tools plugin's <tt>.dylib</tt> file, we get the following information.</p>
<pre class="cpp">libpnp_basictools<span class="operator">.</span>dylib:
libpnp_basictools<span class="operator">.</span>dylib
       (compatibility version <span class="number">0.0.0</span><span class="operator">,</span> current version <span class="number">0.0.0</span>)
<span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
       (compatibility version <span class="number">4.0.0</span><span class="operator">,</span> current version <span class="number">4.0.1</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>Carbon<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>Carbon
       (compatibility version <span class="number">2.0.0</span><span class="operator">,</span> current version <span class="number">128.0.0</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>QuickTime<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>QuickTime
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">10.0.0</span>)
<span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
       (compatibility version <span class="number">4.0.0</span><span class="operator">,</span> current version <span class="number">4.0.1</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libz<span class="operator">.</span><span class="number">1.dylib</span>
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.2.3</span>)
<span class="operator">/</span>System<span class="operator">/</span>Library<span class="operator">/</span>Frameworks<span class="operator">/</span>ApplicationServices<span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span>A<span class="operator">/</span>ApplicationServices
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">22.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libstdc<span class="operator">+</span><span class="operator">+</span><span class="operator">.</span><span class="number">6.dylib</span>
       (compatibility version <span class="number">7.0.0</span><span class="operator">,</span> current version <span class="number">7.3.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libgcc_s<span class="operator">.</span><span class="number">1.dylib</span>
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">1.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libmx<span class="operator">.</span>A<span class="operator">.</span>dylib
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">92.0.0</span>)
<span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>libSystem<span class="operator">.</span>B<span class="operator">.</span>dylib
       (compatibility version <span class="number">1.0.0</span><span class="operator">,</span> current version <span class="number">88.0.0</span>)</pre>
<p>Then we can see that the plugin links to the Qt frameworks it was built against. As we want the plugins to use the framework in the application bundle, we change them the same way as we did for the application. For example for the Basic Tools plugin:</p>
<pre class="cpp">install_name_tool <span class="operator">-</span>change <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>plugins<span class="operator">/</span>libpnp_basictools<span class="operator">.</span>dylib
install_name_tool <span class="operator">-</span>change <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>plugins<span class="operator">/</span>libpnp_basictools<span class="operator">.</span>dylib</pre>
<p>We must also modify the code in <tt>tools/plugandpaint/mainwindow.cpp</tt> to cdUp() to ensure that the application finds the plugins. Add the following code to the <tt>mainwindow.cpp</tt> file:</p>
<pre class="cpp"><span class="preprocessor">#elif defined(Q_OS_MAC)</span>
<span class="keyword">if</span> (pluginsDir<span class="operator">.</span>dirName() <span class="operator">=</span><span class="operator">=</span> <span class="string">&quot;MacOS&quot;</span>) {
    pluginsDir<span class="operator">.</span>cdUp();
}
<span class="preprocessor">#endif</span></pre>
<table class="generic">
 <tr valign="top" class="odd"><td ><img src="images/deployment-mac-application.png" alt="" /></td><td >The additional code in <tt>tools/plugandpaint/mainwindow.cpp</tt> also enables us to view the plugins in the Finder, as shown in the image.<p>We can also add plugins extending Qt, for example adding SQL drivers or image formats. We just need to follow the directory structure outlined in plugin documentation, and make sure they are included in the QCoreApplication::libraryPaths(). Let's quickly do this with the image formats, following the procedure outlined earlier.</p>
<p>Copy Qt's image format plugins into the bundle:</p>
<pre class="cpp">cp <span class="operator">-</span>R <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>plugins<span class="operator">/</span>imageformats
        pluginandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>plugins</pre>
<p>Use <tt>install_name_tool</tt> to link the plugins to the frameworks in the bundle:</p>
<pre class="cpp">install_name_tool <span class="operator">-</span>change <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtGui</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtGui</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>plugins<span class="operator">/</span>imageformats<span class="operator">/</span>libqjpeg<span class="operator">.</span>dylib
install_name_tool <span class="operator">-</span>change <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span>lib<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        @executable_path<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>Frameworks<span class="operator">/</span><span class="type">QtCore</span><span class="operator">.</span>framework<span class="operator">/</span>Versions<span class="operator">/</span><span class="number">4.0</span><span class="operator">/</span><span class="type">QtCore</span>
        plugandpaint<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>plugins<span class="operator">/</span>imageformats<span class="operator">/</span>libqjpeg<span class="operator">.</span>dylib</pre>
<p>Update the source code in <tt>tools/plugandpaint/main.cpp</tt> to look for the new plugins. After constructing the QApplication, we add the following code:</p>
<pre class="cpp"><span class="type">QDir</span> dir(<span class="type">QApplication</span><span class="operator">::</span>applicationDirPath());
dir<span class="operator">.</span>cdUp();
dir<span class="operator">.</span>cd(<span class="string">&quot;plugins&quot;</span>);
<span class="type">QApplication</span><span class="operator">::</span>setLibraryPaths(<span class="type">QStringList</span>(dir<span class="operator">.</span>absolutePath()));</pre>
<p>First, we tell the application to only look for plugins in this directory. In our case, we want the application to look for only those plugins that we distribute with the bundle. If we were part of a bigger Qt installation we could have used QCoreApplication::addLibraryPath() instead.</p>
</td></tr>
</table>
<p><b>Warning:</b> While deploying plugins, we make changes to the source code and that resets the default identification names when the application is rebuilt. So you must repeat the process of making your application link to the correct Qt frameworks in the bundle using <tt>install_name_tool</tt>.</p>
<p>Now you should be able to move the application to another Mac OS X machine and run it without Qt installed. Alternatively, you can move your frameworks that live outside of the bundle to another directory and see if the application still runs.</p>
<p>If you store the frameworks in another location outside the bundle, the technique of linking your application is similar; you must make sure that the application and the frameworks agree where to be looking for the Qt libraries as well as the plugins.</p>
<a name="creating-the-application-package"></a>
<h3>Creating the Application Package</h3>
<p>When you are done linking your application to Qt, either statically or as frameworks, the application is ready to be distributed. For more information, refer to the <a href="https://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/OSXWorkflowGuide/Introduction/Introduction.html">Tools Workflow Guide</a>.</p>
<p>Although the process of deploying an application do have some pitfalls, once you know the various issues you can easily create packages that all your Mac OS X users will enjoy.</p>
<a name="application-dependencies"></a>
<h2>Application Dependencies</h2>
<a name="qt-plugins"></a>
<h3>Qt Plugins</h3>
<p>Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application, and note that each type of plugin must be located within a specific subdirectory (such as <tt>imageformats</tt> or <tt>sqldrivers</tt>) in your distribution directory, as described below.</p>
<p><b>Note: </b>If you are deploying an application that uses QtWebKit to display HTML pages from the World Wide Web, you must include all text codec plugins to support as many HTML encodings possible.</p><p>The search path for Qt plugins (as well as a few other paths) is hard-coded into the QtCore library. By default, the first plugin search path will be hard-coded as <tt>/path/to/Qt/plugins</tt>. But using pre-determined paths has certain disadvantages. For example, they may not exist on the target machine. So you must check various alternatives to ensure that the Qt plugins are found:</p>
<ul>
<li><a href="qt-conf.html">Using <tt>qt.conf</tt></a>. This is the recommended approach as it provides the most flexibility.</li>
<li>Using QApplication::addLibraryPath() or QApplication::setLibraryPaths().</li>
<li>Using a third party installation utility to change the hard-coded paths in the QtCore library.</li>
</ul>
<p>The How to Create Qt Plugins document outlines the issues you need to pay attention to when building and deploying plugins for Qt applications.</p>
<a name="additional-libraries"></a>
<h3>Additional Libraries</h3>
<p>You can check which libraries your application is linking against by using <tt>otool</tt>. Run this with the application path as an argument:</p>
<pre class="cpp">otool <span class="operator">-</span>L MyApp<span class="operator">.</span>app<span class="operator">/</span>Contents<span class="operator">/</span>MacOS<span class="operator">/</span>MyApp</pre>
<p>Unlike the deployment processes on <a href="deployment-x11.html">X11</a> and <a href="deployment-windows.html">Windows</a>, compiler-specific libraries rarely have to be redistributed with your application. But there are several ways to deploy applications, as Qt can be configured, built, and installed in several ways on Mac OS X. Typically your goals help determine how you are going to deploy the application. The last sections describe a few things that you must be aware of while deploying your application.</p>
<a name="mac-os-x-version-dependencies"></a>
<h3>Mac OS X Version Dependencies</h3>
<p>Qt 5 applications can be built and deployed on Mac OS X 10.6 (Snow Leopard) and higher. This is achieved using <i>weak linking</i>. In <i>weak linking</i>, Qt tests whether a function added in a newer version of Mac OS X is available on the computer it is running on. This allows Qt to use newer features when it runs on a newer version of OS X, while remaining compatible on the older versions.</p>
<p>For more information about cross development issues on Mac OS X, see <a href="https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/cross_development/Introduction/Introduction.html">Apple's Developer Website</a>.</p>
<p>The linker is set to be compatible with all OS X versions, so you must change the <tt>MACOSX_DEPLOYMENT_TARGET</tt> environment variable to get <i>weak linking</i> to work for your application. You can add the following:</p>
<pre class="cpp">QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.3</pre>
<p>to your .pro file, and qmake will take care of this for you.</p>
<p>For more information about C++ runtime environment, see <a href="https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/CppRuntimeEnv/CPPRuntimeEnv.html">Apple's Developer Website</a></p>
<a name="the-mac-deployment-tool"></a>
<h2>The Mac Deployment Tool</h2>
<a name="macdeploy"></a><p>The Mac deployment tool can be found in QTDIR/bin/macdeployqt. It is designed to automate the process of creating a deployable application bundle that contains the Qt libraries as private frameworks.</p>
<p>The mac deployment tool also deploys the Qt plugins, according to the following rules:</p>
<ul>
<li>Debug versions of the plugins are not deployed.</li>
<li>The designer plugins are not deployed.</li>
<li>The Image format plugins are always deployed.</li>
<li>SQL driver plugins are deployed if the application uses the QtSql module.</li>
<li>Script plugins are deployed if the application uses the <a href="topics-scripting.html#qtscript">QtScript</a> module.</li>
<li>The svg icon plugin is deployed if the application uses the QtSvg module.</li>
<li>The accessibility plugin is always deployed.</li>
</ul>
<p><b>Note: </b>If you want a 3rd party library to be included in your application bundle, you must copy the library into the bundle manually, after the bundle is created.</p><p><tt>macdeployqt</tt> supports the following options:</p>
<ul>
<li>-no-plugins: Skip plugin deployment</li>
<li>-dmg : Create a .dmg disk image</li>
<li>-no-strip : Don't run 'strip' on the binaries</li>
</ul>
</div>
<!-- @@@deployment-mac.html -->
<p class="naviNextPrevious footerNavi">
</p>
</div>
</div>
</div>
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>