[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
| 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | /*!
|
---|
| 43 | \page deployment.html
|
---|
| 44 | \title Deploying Qt Applications
|
---|
| 45 |
|
---|
| 46 | Deploying an Qt application does not require any C++
|
---|
| 47 | programming. All you need to do is to build Qt and your
|
---|
| 48 | application in release mode, following the procedures described in
|
---|
| 49 | this documentation. We will demonstrate the procedures in terms of
|
---|
| 50 | deploying the \l {tools/plugandpaint}{Plug & Paint} application
|
---|
| 51 | that is provided in Qt's examples directory.
|
---|
| 52 |
|
---|
| 53 | \section1 Static vs. Shared Libraries
|
---|
| 54 |
|
---|
| 55 | There are two ways of deploying an application:
|
---|
| 56 |
|
---|
| 57 | \list
|
---|
| 58 | \o Static Linking
|
---|
| 59 | \o Shared Libraries (Frameworks on Mac)
|
---|
| 60 | \endlist
|
---|
| 61 |
|
---|
| 62 | Static linking results in a stand-alone executable. The advantage
|
---|
| 63 | is that you will only have a few files to deploy. The
|
---|
| 64 | disadvantages are that the executables are large and with no
|
---|
| 65 | flexibility (i.e a new version of the application, or of Qt, will
|
---|
| 66 | require that the deployment process is repeated), and that you
|
---|
| 67 | cannot deploy plugins.
|
---|
| 68 |
|
---|
| 69 | To deploy plugin-based applications, you can use the shared
|
---|
| 70 | library approach. Shared libraries also provide smaller, more
|
---|
| 71 | flexible executables. For example, using the shared library
|
---|
| 72 | approach, the user is able to independently upgrade the Qt library
|
---|
| 73 | used by the application.
|
---|
| 74 |
|
---|
| 75 | Another reason why you might want to use the shared library
|
---|
| 76 | approach, is if you want to use the same Qt libraries for a family
|
---|
| 77 | of applications. In fact, if you download the binary installation
|
---|
| 78 | of Qt, you get Qt as a shared library.
|
---|
| 79 |
|
---|
| 80 | The disadvantage with the shared library approach is that you
|
---|
| 81 | will get more files to deploy. For more information, see
|
---|
| 82 | \l{sharedlibrary.html}{Creating Shared Libraries}.
|
---|
| 83 |
|
---|
| 84 | \section1 Deploying Qt's Libraries
|
---|
| 85 |
|
---|
| 86 | \table
|
---|
| 87 | \header
|
---|
| 88 | \o {4,1} Qt's Libraries
|
---|
| 89 | \row
|
---|
| 90 | \o \l {QtAssistant}
|
---|
| 91 | \o \l {QAxContainer}
|
---|
| 92 | \o \l {QAxServer}
|
---|
| 93 | \o \l {QtCore}
|
---|
| 94 | \row
|
---|
| 95 | \o \l {QtDBus}
|
---|
| 96 | \o \l {QtDesigner}
|
---|
| 97 | \o \l {QtGui}
|
---|
| 98 | \o \l {QtHelp}
|
---|
| 99 | \row
|
---|
| 100 | \o \l {QtNetwork}
|
---|
| 101 | \o \l {QtOpenGL}
|
---|
| 102 | \o \l {QtScript}
|
---|
| 103 | \o \l {QtScriptTools}
|
---|
| 104 | \row
|
---|
| 105 | \o \l {QtSql}
|
---|
| 106 | \o \l {QtSvg}
|
---|
| 107 | \o \l {QtWebKit}
|
---|
| 108 | \o \l {QtXml}
|
---|
| 109 | \row
|
---|
| 110 | \o \l {QtXmlPatterns}
|
---|
| 111 | \o \l {Phonon Module}{Phonon}
|
---|
| 112 | \o \l {Qt3Support}
|
---|
| 113 | \endtable
|
---|
| 114 |
|
---|
| 115 | Since Qt is not a system library, it has to be redistributed along
|
---|
| 116 | with your application; the minimum is to redistribute the run-time
|
---|
| 117 | of the libraries used by the application. Using static linking,
|
---|
| 118 | however, the Qt run-time is compiled into the executable.
|
---|
| 119 |
|
---|
| 120 | In particular, you will need to deploy Qt plugins, such as
|
---|
| 121 | JPEG support or SQL drivers. For more information about plugins,
|
---|
| 122 | see the \l {plugins-howto.html}{How to Create Qt Plugins}
|
---|
| 123 | documentation.
|
---|
| 124 |
|
---|
| 125 | When deploying an application using the shared library approach
|
---|
| 126 | you must ensure that the Qt libraries will use the correct path to
|
---|
| 127 | find the Qt plugins, documentation, translation etc. To do this you
|
---|
| 128 | can use a \c qt.conf file. For more information, see the \l {Using
|
---|
| 129 | qt.conf} documentation.
|
---|
| 130 |
|
---|
| 131 | Depending on configuration, compiler specific libraries must be
|
---|
| 132 | redistributed as well. For more information, see the platform
|
---|
| 133 | specific Application Dependencies sections: \l
|
---|
| 134 | {deployment-x11.html#application-dependencies}{X11}, \l
|
---|
| 135 | {deployment-windows.html#application-dependencies}{Windows}, \l
|
---|
| 136 | {deployment-mac.html#application-dependencies}{Mac}.
|
---|
| 137 |
|
---|
| 138 | \section1 Licensing
|
---|
| 139 |
|
---|
| 140 | Some of Qt's libraries are based on third party libraries that are
|
---|
| 141 | not licensed using the same dual-license model as Qt. As a result,
|
---|
| 142 | care must be taken when deploying applications that use these
|
---|
| 143 | libraries, particularly when the application is statically linked
|
---|
| 144 | to them.
|
---|
| 145 |
|
---|
| 146 | The following table contains an inexhaustive summary of the issues
|
---|
| 147 | you should be aware of.
|
---|
| 148 |
|
---|
| 149 | \table
|
---|
| 150 | \header \o Qt Library \o Dependency
|
---|
| 151 | \o Licensing Issue
|
---|
| 152 | \row \o QtHelp \o CLucene
|
---|
| 153 | \o The version of clucene distributed with Qt is licensed
|
---|
| 154 | under the GNU LGPL version 2.1 or later. This has implications for
|
---|
| 155 | developers of closed source applications. Please see
|
---|
| 156 | \l{QtHelp Module#License Information}{the QtHelp module documentation}
|
---|
| 157 | for more information.
|
---|
| 158 |
|
---|
| 159 | \row \o QtNetwork \o OpenSSL
|
---|
| 160 | \o Some configurations of QtNetwork use OpenSSL at run-time. Deployment
|
---|
| 161 | of OpenSSL libraries is subject to both licensing and export restrictions.
|
---|
| 162 | More information can be found in the \l{Secure Sockets Layer (SSL) Classes}
|
---|
| 163 | documentation.
|
---|
| 164 |
|
---|
| 165 | \row \o QtWebKit \o WebKit
|
---|
| 166 | \o WebKit is licensed under the GNU LGPL version 2 or later.
|
---|
| 167 | This has implications for developers of closed source applications.
|
---|
| 168 | Please see \l{QtWebKit Module#License Information}{the QtWebKit module
|
---|
| 169 | documentation} for more information.
|
---|
| 170 |
|
---|
| 171 | \row \o \l{Phonon Module}{Phonon} \o Phonon
|
---|
| 172 | \o Phonon relies on the native multimedia engines on different platforms.
|
---|
| 173 | Phonon itself is licensed under the GNU LGPL version 2. Please see
|
---|
| 174 | \l{Phonon Module#License Information}{the Phonon module documentation}
|
---|
| 175 | for more information on licensing and the
|
---|
| 176 | \l{Phonon Overview#Backends}{Phonon Overview} for details of the backends
|
---|
| 177 | in use on different platforms.
|
---|
| 178 | \endtable
|
---|
| 179 |
|
---|
| 180 | \section1 Platform-Specific Notes
|
---|
| 181 |
|
---|
| 182 | The procedure of deploying Qt applications is different for the
|
---|
| 183 | various platforms:
|
---|
| 184 |
|
---|
| 185 | \list
|
---|
| 186 | \o \l{Deploying an Application on X11 Platforms}{Qt for X11 Platforms}
|
---|
| 187 | \o \l{Deploying an Application on Windows}{Qt for Windows}
|
---|
| 188 | \o \l{Deploying an Application on Mac OS X}{Qt for Mac OS X}
|
---|
| 189 | \o \l{Deploying Qt for Embedded Linux Applications}{Qt for Embedded Linux}
|
---|
| 190 | \o \l{Deploying an Application on the Symbian platform}{Qt for the Symbian platform}
|
---|
| 191 | \endlist
|
---|
| 192 |
|
---|
| 193 | \sa Installation {Platform-Specific Documentation}
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | /*!
|
---|
| 197 | \page deployment-x11.html
|
---|
| 198 | \contentspage Deploying Qt Applications
|
---|
| 199 |
|
---|
| 200 | \title Deploying an Application on X11 Platforms
|
---|
| 201 |
|
---|
| 202 | Due to the proliferation of Unix systems (commercial Unices, Linux
|
---|
| 203 | distributions, etc.), deployment on Unix is a complex
|
---|
| 204 | topic. Before we start, be aware that programs compiled for one
|
---|
| 205 | Unix flavor will probably not run on a different Unix system. For
|
---|
| 206 | example, unless you use a cross-compiler, you cannot compile your
|
---|
| 207 | application on Irix and distribute it on AIX.
|
---|
| 208 |
|
---|
| 209 | Contents:
|
---|
| 210 |
|
---|
| 211 | \tableofcontents
|
---|
| 212 |
|
---|
| 213 | This documentation will describe how to determine which files you
|
---|
| 214 | should include in your distribution, and how to make sure that the
|
---|
| 215 | application will find them at run-time. We will demonstrate the
|
---|
| 216 | procedures in terms of deploying the \l {tools/plugandpaint}{Plug
|
---|
| 217 | & Paint} application that is provided in Qt's examples directory.
|
---|
| 218 |
|
---|
| 219 | \section1 Static Linking
|
---|
| 220 |
|
---|
| 221 | Static linking is often the safest and easiest way to distribute
|
---|
| 222 | an application on Unix since it relieves you from the task of
|
---|
| 223 | distributing the Qt libraries and ensuring that they are located
|
---|
| 224 | in the default search path for libraries on the target system.
|
---|
| 225 |
|
---|
| 226 | \section2 Building Qt Statically
|
---|
| 227 |
|
---|
| 228 | To use this approach, you must start by installing a static version
|
---|
| 229 | of the Qt library:
|
---|
| 230 |
|
---|
| 231 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 0
|
---|
| 232 |
|
---|
| 233 | We specify the prefix so that we do not overwrite the existing Qt
|
---|
| 234 | installation. The example above only builds the Qt libraries,
|
---|
| 235 | i.e. the examples and Qt Designer will not be built. When \c make
|
---|
| 236 | is done, you will find the Qt libraries in the \c /path/to/Qt/lib
|
---|
| 237 | directory.
|
---|
| 238 |
|
---|
| 239 | When linking your application against static Qt libraries, note
|
---|
| 240 | that you might need to add more libraries to the \c LIBS line in
|
---|
| 241 | your project file. For more information, see the \l {Application
|
---|
| 242 | Dependencies} section.
|
---|
| 243 |
|
---|
| 244 | \section2 Linking the Application to the Static Version of Qt
|
---|
| 245 |
|
---|
| 246 | Once Qt is built statically, the next step is to regenerate the
|
---|
| 247 | makefile and rebuild the application. First, we must go into the
|
---|
| 248 | directory that contains the application:
|
---|
| 249 |
|
---|
| 250 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 1
|
---|
| 251 |
|
---|
| 252 | Now run qmake to create a new makefile for the application, and do
|
---|
| 253 | a clean build to create the statically linked executable:
|
---|
| 254 |
|
---|
| 255 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 2
|
---|
| 256 |
|
---|
| 257 | You probably want to link against the release libraries, and you
|
---|
| 258 | can specify this when invoking \c qmake. Note that we must set the
|
---|
| 259 | path to the static Qt that we just built.
|
---|
| 260 |
|
---|
| 261 | To check that the application really links statically with Qt, run
|
---|
| 262 | the \c ldd tool (available on most Unices):
|
---|
| 263 |
|
---|
| 264 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 3
|
---|
| 265 |
|
---|
| 266 | Verify that the Qt libraries are not mentioned in the output.
|
---|
| 267 |
|
---|
| 268 | Now, provided that everything compiled and linked without any
|
---|
| 269 | errors, we should have a \c plugandpaint file that is ready for
|
---|
| 270 | deployment. One easy way to check that the application really can
|
---|
| 271 | be run stand-alone is to copy it to a machine that doesn't have Qt
|
---|
| 272 | or any Qt applications installed, and run it on that machine.
|
---|
| 273 |
|
---|
| 274 | Remember that if your application depends on compiler specific
|
---|
| 275 | libraries, these must still be redistributed along with your
|
---|
| 276 | application. For more information, see the \l {Application
|
---|
| 277 | Dependencies} section.
|
---|
| 278 |
|
---|
| 279 | The \l {tools/plugandpaint}{Plug & Paint} example consists of
|
---|
| 280 | several components: The core application (\l
|
---|
| 281 | {tools/plugandpaint}{Plug & Paint}), and the \l
|
---|
| 282 | {tools/plugandpaintplugins/basictools}{Basic Tools} and \l
|
---|
| 283 | {tools/plugandpaintplugins/extrafilters}{Extra Filters}
|
---|
| 284 | plugins. Since we cannot deploy plugins using the static linking
|
---|
| 285 | approach, the executable we have prepared so far is
|
---|
| 286 | incomplete. The application will run, but the functionality will
|
---|
| 287 | be disabled due to the missing plugins. To deploy plugin-based
|
---|
| 288 | applications we should use the shared library approach.
|
---|
| 289 |
|
---|
| 290 | \section1 Shared Libraries
|
---|
| 291 |
|
---|
| 292 | We have two challenges when deploying the \l
|
---|
| 293 | {tools/plugandpaint}{Plug & Paint} application using the shared
|
---|
| 294 | libraries approach: The Qt runtime has to be correctly
|
---|
| 295 | redistributed along with the application executable, and the
|
---|
| 296 | plugins have to be installed in the correct location on the target
|
---|
| 297 | system so that the application can find them.
|
---|
| 298 |
|
---|
| 299 | \section2 Building Qt as a Shared Library
|
---|
| 300 |
|
---|
| 301 | We assume that you already have installed Qt as a shared library,
|
---|
| 302 | which is the default when installing Qt, in the \c /path/to/Qt
|
---|
| 303 | directory. For more information on how to build Qt, see the \l
|
---|
| 304 | {Installation} documentation.
|
---|
| 305 |
|
---|
| 306 | \section2 Linking the Application to Qt as a Shared Library
|
---|
| 307 |
|
---|
| 308 | After ensuring that Qt is built as a shared library, we can build
|
---|
| 309 | the \l {tools/plugandpaint}{Plug & Paint} application. First, we
|
---|
| 310 | must go into the directory that contains the application:
|
---|
| 311 |
|
---|
| 312 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 4
|
---|
| 313 |
|
---|
| 314 | Now run qmake to create a new makefile for the application, and do
|
---|
| 315 | a clean build to create the dynamically linked executable:
|
---|
| 316 |
|
---|
| 317 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 5
|
---|
| 318 |
|
---|
| 319 | This builds the core application, the following will build the
|
---|
| 320 | plugins:
|
---|
| 321 |
|
---|
| 322 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 6
|
---|
| 323 |
|
---|
| 324 | If everything compiled and linked without any errors, we will get
|
---|
| 325 | a \c plugandpaint executable and the \c libpnp_basictools.so and
|
---|
| 326 | \c libpnp_extrafilters.so plugin files.
|
---|
| 327 |
|
---|
| 328 | \section2 Creating the Application Package
|
---|
| 329 |
|
---|
| 330 | There is no standard package management on Unix, so the method we
|
---|
| 331 | present below is a generic solution. See the documentation for
|
---|
| 332 | your target system for information on how to create a package.
|
---|
| 333 |
|
---|
| 334 | To deploy the application, we must make sure that we copy the
|
---|
| 335 | relevant Qt libraries (corresponding to the Qt modules used in the
|
---|
| 336 | application) as well as the executable to the same
|
---|
| 337 | directory. Remember that if your application depends on compiler
|
---|
| 338 | specific libraries, these must also be redistributed along with
|
---|
| 339 | your application. For more information, see the \l {Application
|
---|
| 340 | Dependencies} section.
|
---|
| 341 |
|
---|
| 342 | We'll cover the plugins shortly, but the main issue with shared
|
---|
| 343 | libraries is that you must ensure that the dynamic linker will
|
---|
| 344 | find the Qt libraries. Unless told otherwise, the dynamic linker
|
---|
| 345 | doesn't search the directory where your application resides. There
|
---|
| 346 | are many ways to solve this:
|
---|
| 347 |
|
---|
| 348 | \list
|
---|
| 349 |
|
---|
| 350 | \o You can install the Qt libraries in one of the system
|
---|
| 351 | library paths (e.g. \c /usr/lib on most systems).
|
---|
| 352 |
|
---|
| 353 | \o You can pass a predetermined path to the \c -rpath command-line
|
---|
| 354 | option when linking the application. This will tell the dynamic
|
---|
| 355 | linker to look in this directory when starting your application.
|
---|
| 356 |
|
---|
| 357 | \o You can write a startup script for your application, where you
|
---|
| 358 | modify the dynamic linker configuration (e.g. adding your
|
---|
| 359 | application's directory to the \c LD_LIBRARY_PATH environment
|
---|
| 360 | variable. \note If your application will be running with "Set
|
---|
| 361 | user ID on execution," and if it will be owned by root, then
|
---|
| 362 | LD_LIBRARY_PATH will be ignored on some platforms. In this
|
---|
| 363 | case, use of the LD_LIBRARY_PATH approach is not an option).
|
---|
| 364 |
|
---|
| 365 | \endlist
|
---|
| 366 |
|
---|
| 367 | The disadvantage of the first approach is that the user must have
|
---|
| 368 | super user privileges. The disadvantage of the second approach is
|
---|
| 369 | that the user may not have privileges to install into the
|
---|
| 370 | predetemined path. In either case, the users don't have the option
|
---|
| 371 | of installing to their home directory. We recommend using the
|
---|
| 372 | third approach since it is the most flexible. For example, a \c
|
---|
| 373 | plugandpaint.sh script will look like this:
|
---|
| 374 |
|
---|
| 375 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 7
|
---|
| 376 |
|
---|
| 377 | By running this script instead of the executable, you are sure
|
---|
| 378 | that the Qt libraries will be found by the dynamic linker. Note
|
---|
| 379 | that you only have to rename the script to use it with other
|
---|
| 380 | applications.
|
---|
| 381 |
|
---|
| 382 | When looking for plugins, the application searches in a plugins
|
---|
| 383 | subdirectory inside the directory of the application
|
---|
| 384 | executable. Either you have to manually copy the plugins into the
|
---|
| 385 | \c plugins directory, or you can set the \c DESTDIR in the
|
---|
| 386 | plugins' project files:
|
---|
| 387 |
|
---|
| 388 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 8
|
---|
| 389 |
|
---|
| 390 | An archive distributing all the Qt libraries, and all the plugins,
|
---|
| 391 | required to run the \l {tools/plugandpaint}{Plug & Paint}
|
---|
| 392 | application, would have to include the following files:
|
---|
| 393 |
|
---|
| 394 | \table 100%
|
---|
| 395 | \header
|
---|
| 396 | \o Component \o {2, 1} File Name
|
---|
| 397 | \row
|
---|
| 398 | \o The executable
|
---|
| 399 | \o {2, 1} \c plugandpaint
|
---|
| 400 | \row
|
---|
| 401 | \o The script to run the executable
|
---|
| 402 | \o {2, 1} \c plugandpaint.sh
|
---|
| 403 | \row
|
---|
| 404 | \o The Basic Tools plugin
|
---|
| 405 | \o {2, 1} \c plugins\libpnp_basictools.so
|
---|
| 406 | \row
|
---|
| 407 | \o The ExtraFilters plugin
|
---|
| 408 | \o {2, 1} \c plugins\libpnp_extrafilters.so
|
---|
| 409 | \row
|
---|
| 410 | \o The Qt Core module
|
---|
| 411 | \o {2, 1} \c libQtCore.so.4
|
---|
| 412 | \row
|
---|
| 413 | \o The Qt GUI module
|
---|
| 414 | \o {2, 1} \c libQtGui.so.4
|
---|
| 415 | \endtable
|
---|
| 416 |
|
---|
| 417 | On most systems, the extension for shared libraries is \c .so. A
|
---|
| 418 | notable exception is HP-UX, which uses \c .sl.
|
---|
| 419 |
|
---|
| 420 | Remember that if your application depends on compiler specific
|
---|
| 421 | libraries, these must still be redistributed along with your
|
---|
| 422 | application. For more information, see the \l {Application
|
---|
| 423 | Dependencies} section.
|
---|
| 424 |
|
---|
| 425 | To verify that the application now can be successfully deployed,
|
---|
| 426 | you can extract this archive on a machine without Qt and without
|
---|
| 427 | any compiler installed, and try to run it, i.e. run the \c
|
---|
| 428 | plugandpaint.sh script.
|
---|
| 429 |
|
---|
| 430 | An alternative to putting the plugins in the \c plugins
|
---|
| 431 | subdirectory is to add a custom search path when you start your
|
---|
| 432 | application using QApplication::addLibraryPath() or
|
---|
| 433 | QApplication::setLibraryPaths().
|
---|
| 434 |
|
---|
| 435 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 9
|
---|
| 436 |
|
---|
| 437 | \section1 Application Dependencies
|
---|
| 438 |
|
---|
| 439 | \section2 Additional Libraries
|
---|
| 440 |
|
---|
| 441 | To find out which libraries your application depends on, run the
|
---|
| 442 | \c ldd tool (available on most Unices):
|
---|
| 443 |
|
---|
| 444 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 10
|
---|
| 445 |
|
---|
| 446 | This will list all the shared library dependencies for your
|
---|
| 447 | application. Depending on configuration, these libraries must be
|
---|
| 448 | redistributed along with your application. In particular, the
|
---|
| 449 | standard C++ library must be redistributed if you're compiling
|
---|
| 450 | your application with a compiler that is binary incompatible with
|
---|
| 451 | the system compiler. When possible, the safest solution is to link
|
---|
| 452 | against these libraries statically.
|
---|
| 453 |
|
---|
| 454 | You will probably want to link dynamically with the regular X11
|
---|
| 455 | libraries, since some implementations will try to open other
|
---|
| 456 | shared libraries with \c dlopen(), and if this fails, the X11
|
---|
| 457 | library might cause your application to crash.
|
---|
| 458 |
|
---|
| 459 | It's also worth mentioning that Qt will look for certain X11
|
---|
| 460 | extensions, such as Xinerama and Xrandr, and possibly pull them
|
---|
| 461 | in, including all the libraries that they link against. If you
|
---|
| 462 | can't guarantee the presence of a certain extension, the safest
|
---|
| 463 | approach is to disable it when configuring Qt (e.g. \c {./configure
|
---|
| 464 | -no-xrandr}).
|
---|
| 465 |
|
---|
| 466 | FontConfig and FreeType are other examples of libraries that
|
---|
| 467 | aren't always available or that aren't always binary
|
---|
| 468 | compatible. As strange as it may sound, some software vendors have
|
---|
| 469 | had success by compiling their software on very old machines and
|
---|
| 470 | have been very careful not to upgrade any of the software running
|
---|
| 471 | on them.
|
---|
| 472 |
|
---|
| 473 | When linking your application against the static Qt libraries, you
|
---|
| 474 | must explicitly link with the dependent libraries mentioned
|
---|
| 475 | above. Do this by adding them to the \c LIBS variable in your
|
---|
| 476 | project file.
|
---|
| 477 |
|
---|
| 478 | \section2 Qt Plugins
|
---|
| 479 |
|
---|
| 480 | Your application may also depend on one or more Qt plugins, such
|
---|
| 481 | as the JPEG image format plugin or a SQL driver plugin. Be sure
|
---|
| 482 | to distribute any Qt plugins that you need with your application,
|
---|
| 483 | and note that each type of plugin should be located within a
|
---|
| 484 | specific subdirectory (such as \c imageformats or \c sqldrivers)
|
---|
| 485 | within your distribution directory, as described below.
|
---|
| 486 |
|
---|
| 487 | \note If you are deploying an application that uses QtWebKit to display
|
---|
| 488 | HTML pages from the World Wide Web, you should include all text codec
|
---|
| 489 | plugins to support as many HTML encodings possible.
|
---|
| 490 |
|
---|
| 491 | The search path for Qt plugins (as well as a few other paths) is
|
---|
| 492 | hard-coded into the QtCore library. By default, the first plugin
|
---|
| 493 | search path will be hard-coded as \c /path/to/Qt/plugins. As
|
---|
| 494 | mentioned above, using pre-determined paths has certain
|
---|
| 495 | disadvantages, so you need to examine various alternatives to make
|
---|
| 496 | sure that the Qt plugins are found:
|
---|
| 497 |
|
---|
| 498 | \list
|
---|
| 499 |
|
---|
| 500 | \o \l{qt-conf.html}{Using \c qt.conf}. This is the recommended
|
---|
| 501 | approach since it provides the most flexibility.
|
---|
| 502 |
|
---|
| 503 | \o Using QApplication::addLibraryPath() or
|
---|
| 504 | QApplication::setLibraryPaths().
|
---|
| 505 |
|
---|
| 506 | \o Using a third party installation utility or the target system's
|
---|
| 507 | package manager to change the hard-coded paths in the QtCore
|
---|
| 508 | library.
|
---|
| 509 |
|
---|
| 510 | \endlist
|
---|
| 511 |
|
---|
| 512 | The \l{How to Create Qt Plugins} document outlines the issues you
|
---|
| 513 | need to pay attention to when building and deploying plugins for
|
---|
| 514 | Qt applications.
|
---|
| 515 | */
|
---|
| 516 |
|
---|
| 517 | /*!
|
---|
| 518 | \page deployment-windows.html
|
---|
| 519 | \contentspage Deploying Qt Applications
|
---|
| 520 |
|
---|
| 521 | \title Deploying an Application on Windows
|
---|
| 522 |
|
---|
| 523 | This documentation will describe how to determine which files you
|
---|
| 524 | should include in your distribution, and how to make sure that the
|
---|
| 525 | application will find them at run-time. We will demonstrate the
|
---|
| 526 | procedures in terms of deploying the \l {tools/plugandpaint}{Plug
|
---|
| 527 | & Paint} application that is provided in Qt's examples directory.
|
---|
| 528 |
|
---|
| 529 | Contents:
|
---|
| 530 |
|
---|
| 531 | \tableofcontents
|
---|
| 532 |
|
---|
| 533 | \section1 Static Linking
|
---|
| 534 |
|
---|
| 535 | If you want to keep things simple by only having a few files to
|
---|
| 536 | deploy, i.e. a stand-alone executable with the associated compiler
|
---|
| 537 | specific DLLs, then you must build everything statically.
|
---|
| 538 |
|
---|
| 539 | \section2 Building Qt Statically
|
---|
| 540 |
|
---|
| 541 | Before we can build our application we must make sure that Qt is
|
---|
| 542 | built statically. To do this, go to a command prompt and type the
|
---|
| 543 | following:
|
---|
| 544 |
|
---|
| 545 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 11
|
---|
| 546 |
|
---|
| 547 | Remember to specify any other options you need, such as data base
|
---|
| 548 | drivers, as arguments to \c configure. Once \c configure has
|
---|
| 549 | finished, type the following:
|
---|
| 550 |
|
---|
| 551 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 12
|
---|
| 552 |
|
---|
| 553 | This will build Qt statically. Note that unlike with a dynamic build,
|
---|
| 554 | building Qt statically will result in libraries without version numbers;
|
---|
| 555 | e.g. \c QtCore4.lib will be \c QtCore.lib. Also, we have used \c nmake
|
---|
| 556 | in all the examples, but if you use MinGW you must use
|
---|
| 557 | \c mingw32-make instead.
|
---|
| 558 |
|
---|
| 559 | \note If you later need to reconfigure and rebuild Qt from the
|
---|
| 560 | same location, ensure that all traces of the previous configuration are
|
---|
| 561 | removed by entering the build directory and typing \c{nmake distclean}
|
---|
| 562 | before running \c configure again.
|
---|
| 563 |
|
---|
| 564 | \section2 Linking the Application to the Static Version of Qt
|
---|
| 565 |
|
---|
| 566 | Once Qt has finished building we can build the \l
|
---|
| 567 | {tools/plugandpaint}{Plug & Paint} application. First we must go
|
---|
| 568 | into the directory that contains the application:
|
---|
| 569 |
|
---|
| 570 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 13
|
---|
| 571 |
|
---|
| 572 | We must then run \c qmake to create a new makefile for the
|
---|
| 573 | application, and do a clean build to create the statically linked
|
---|
| 574 | executable:
|
---|
| 575 |
|
---|
| 576 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 14
|
---|
| 577 |
|
---|
| 578 | You probably want to link against the release libraries, and you
|
---|
| 579 | can specify this when invoking \c qmake. Now, provided that
|
---|
| 580 | everything compiled and linked without any errors, we should have
|
---|
| 581 | a \c plugandpaint.exe file that is ready for deployment. One easy
|
---|
| 582 | way to check that the application really can be run stand-alone is
|
---|
| 583 | to copy it to a machine that doesn't have Qt or any Qt
|
---|
| 584 | applications installed, and run it on that machine.
|
---|
| 585 |
|
---|
| 586 | Remember that if your application depends on compiler specific
|
---|
| 587 | libraries, these must still be redistributed along with your
|
---|
| 588 | application. You can check which libraries your application is
|
---|
| 589 | linking against by using the \c depends tool. For more
|
---|
| 590 | information, see the \l {Application Dependencies} section.
|
---|
| 591 |
|
---|
| 592 | The \l {tools/plugandpaint}{Plug & Paint} example consists of
|
---|
| 593 | several components: The application itself (\l
|
---|
| 594 | {tools/plugandpaint}{Plug & Paint}), and the \l
|
---|
| 595 | {tools/plugandpaintplugins/basictools}{Basic Tools} and \l
|
---|
| 596 | {tools/plugandpaintplugins/extrafilters}{Extra Filters}
|
---|
| 597 | plugins. Since we cannot deploy plugins using the static linking
|
---|
| 598 | approach, the application we have prepared is incomplete. It will
|
---|
| 599 | run, but the functionality will be disabled due to the missing
|
---|
| 600 | plugins. To deploy plugin-based applications we should use the
|
---|
| 601 | shared library approach.
|
---|
| 602 |
|
---|
| 603 | \section1 Shared Libraries
|
---|
| 604 |
|
---|
| 605 | We have two challenges when deploying the \l
|
---|
| 606 | {tools/plugandpaint}{Plug & Paint} application using the shared
|
---|
| 607 | libraries approach: The Qt runtime has to be correctly
|
---|
| 608 | redistributed along with the application executable, and the
|
---|
| 609 | plugins have to be installed in the correct location on the target
|
---|
| 610 | system so that the application can find them.
|
---|
| 611 |
|
---|
| 612 | \section2 Building Qt as a Shared Library
|
---|
| 613 |
|
---|
| 614 | We assume that you already have installed Qt as a shared library,
|
---|
| 615 | which is the default when installing Qt, in the \c C:\path\to\Qt
|
---|
| 616 | directory. For more information on how to build Qt, see the \l
|
---|
| 617 | {Installation} documentation.
|
---|
| 618 |
|
---|
| 619 | \section2 Linking the Application to Qt as a Shared Library
|
---|
| 620 |
|
---|
| 621 | After ensuring that Qt is built as a shared library, we can build
|
---|
| 622 | the \l {tools/plugandpaint}{Plug & Paint} application. First, we
|
---|
| 623 | must go into the directory that contains the application:
|
---|
| 624 |
|
---|
| 625 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 15
|
---|
| 626 |
|
---|
| 627 | Now run \c qmake to create a new makefile for the application, and
|
---|
| 628 | do a clean build to create the dynamically linked executable:
|
---|
| 629 |
|
---|
| 630 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 16
|
---|
| 631 |
|
---|
| 632 | This builds the core application, the following will build the
|
---|
| 633 | plugins:
|
---|
| 634 |
|
---|
| 635 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 17
|
---|
| 636 |
|
---|
| 637 | If everything compiled and linked without any errors, we will get
|
---|
| 638 | a \c plugandpaint.exe executable and the \c pnp_basictools.dll and
|
---|
| 639 | \c pnp_extrafilters.dll plugin files.
|
---|
| 640 |
|
---|
| 641 | \section2 Creating the Application Package
|
---|
| 642 |
|
---|
| 643 | To deploy the application, we must make sure that we copy the
|
---|
| 644 | relevant Qt DLL (corresponding to the Qt modules used in
|
---|
| 645 | the application) as well as the executable to the same directory
|
---|
| 646 | in the \c release subdirectory.
|
---|
| 647 |
|
---|
| 648 | Remember that if your application depends on compiler specific
|
---|
| 649 | libraries, these must be redistributed along with your
|
---|
| 650 | application. You can check which libraries your application is
|
---|
| 651 | linking against by using the \c depends tool. For more
|
---|
| 652 | information, see the \l {Application Dependencies} section.
|
---|
| 653 |
|
---|
| 654 | We'll cover the plugins shortly, but first we'll check that the
|
---|
| 655 | application will work in a deployed environment: Either copy the
|
---|
| 656 | executable and the Qt DLLs to a machine that doesn't have Qt
|
---|
| 657 | or any Qt applications installed, or if you want to test on the
|
---|
| 658 | build machine, ensure that the machine doesn't have Qt in its
|
---|
| 659 | environment.
|
---|
| 660 |
|
---|
| 661 | If the application starts without any problems, then we have
|
---|
| 662 | successfully made a dynamically linked version of the \l
|
---|
| 663 | {tools/plugandpaint}{Plug & Paint} application. But the
|
---|
| 664 | application's functionality will still be missing since we have
|
---|
| 665 | not yet deployed the associated plugins.
|
---|
| 666 |
|
---|
| 667 | Plugins work differently to normal DLLs, so we can't just
|
---|
| 668 | copy them into the same directory as our application's executable
|
---|
| 669 | as we did with the Qt DLLs. When looking for plugins, the
|
---|
| 670 | application searches in a \c plugins subdirectory inside the
|
---|
| 671 | directory of the application executable.
|
---|
| 672 |
|
---|
| 673 | So to make the plugins available to our application, we have to
|
---|
| 674 | create the \c plugins subdirectory and copy over the relevant DLLs:
|
---|
| 675 |
|
---|
| 676 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 18
|
---|
| 677 |
|
---|
| 678 | An archive distributing all the Qt DLLs and application
|
---|
| 679 | specific plugins required to run the \l {tools/plugandpaint}{Plug
|
---|
| 680 | & Paint} application, would have to include the following files:
|
---|
| 681 |
|
---|
| 682 | \table 100%
|
---|
| 683 | \header
|
---|
| 684 | \o Component \o {2, 1} File Name
|
---|
| 685 | \row
|
---|
| 686 | \o The executable
|
---|
| 687 | \o {2, 1} \c plugandpaint.exe
|
---|
| 688 | \row
|
---|
| 689 | \o The Basic Tools plugin
|
---|
| 690 | \o {2, 1} \c plugins\pnp_basictools.dll
|
---|
| 691 | \row
|
---|
| 692 | \o The ExtraFilters plugin
|
---|
| 693 | \o {2, 1} \c plugins\pnp_extrafilters.dll
|
---|
| 694 | \row
|
---|
| 695 | \o The Qt Core module
|
---|
| 696 | \o {2, 1} \c qtcore4.dll
|
---|
| 697 | \row
|
---|
| 698 | \o The Qt GUI module
|
---|
| 699 | \o {2, 1} \c qtgui4.dll
|
---|
| 700 | \endtable
|
---|
| 701 |
|
---|
| 702 | In addition, the archive must contain the following compiler
|
---|
| 703 | specific libraries depending on your version of Visual Studio:
|
---|
| 704 |
|
---|
| 705 | \table 100%
|
---|
| 706 | \header
|
---|
| 707 | \o \o VC++ 6.0 \o VC++ 7.1 (2003) \o VC++ 8.0 (2005) \o VC++ 9.0 (2008)
|
---|
| 708 | \row
|
---|
| 709 | \o The C run-time
|
---|
| 710 | \o \c msvcrt.dll
|
---|
| 711 | \o \c msvcr71.dll
|
---|
| 712 | \o \c msvcr80.dll
|
---|
| 713 | \o \c msvcr90.dll
|
---|
| 714 | \row
|
---|
| 715 | \o The C++ run-time
|
---|
| 716 | \o \c msvcp60.dll
|
---|
| 717 | \o \c msvcp71.dll
|
---|
| 718 | \o \c msvcp80.dll
|
---|
| 719 | \o \c msvcp90.dll
|
---|
| 720 | \endtable
|
---|
| 721 |
|
---|
| 722 | To verify that the application now can be successfully deployed,
|
---|
| 723 | you can extract this archive on a machine without Qt and without
|
---|
| 724 | any compiler installed, and try to run it.
|
---|
| 725 |
|
---|
| 726 | An alternative to putting the plugins in the plugins subdirectory
|
---|
| 727 | is to add a custom search path when you start your application
|
---|
| 728 | using QApplication::addLibraryPath() or
|
---|
| 729 | QApplication::setLibraryPaths().
|
---|
| 730 |
|
---|
| 731 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 19
|
---|
| 732 |
|
---|
| 733 | One benefit of using plugins is that they can easily be made
|
---|
| 734 | available to a whole family of applications.
|
---|
| 735 |
|
---|
| 736 | It's often most convenient to add the path in the application's \c
|
---|
| 737 | main() function, right after the QApplication object is
|
---|
| 738 | created. Once the path is added, the application will search it
|
---|
| 739 | for plugins, in addition to looking in the \c plugins subdirectory
|
---|
| 740 | in the application's own directory. Any number of additional paths
|
---|
| 741 | can be added.
|
---|
| 742 |
|
---|
| 743 | \section2 Visual Studio 2005 Onwards
|
---|
| 744 |
|
---|
| 745 | When deploying an application compiled with Visual Studio 2005 onwards,
|
---|
| 746 | there are some additional steps to be taken.
|
---|
| 747 |
|
---|
| 748 | First, we need to copy the manifest file created when linking the
|
---|
| 749 | application. This manifest file contains information about the
|
---|
| 750 | application's dependencies on side-by-side assemblies, such as the runtime
|
---|
| 751 | libraries.
|
---|
| 752 |
|
---|
| 753 | The manifest file needs to be copied into the \bold same folder as the
|
---|
| 754 | application executable. You do not need to copy the manifest files for
|
---|
| 755 | shared libraries (DLLs), since they are not used.
|
---|
| 756 |
|
---|
| 757 | If the shared library has dependencies that are different from the
|
---|
| 758 | application using it, the manifest file needs to be embedded into the DLL
|
---|
| 759 | binary. Since Qt 4.1.3, the follwoing \c CONFIG options are available for
|
---|
| 760 | embedding manifests:
|
---|
| 761 |
|
---|
| 762 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 20
|
---|
| 763 |
|
---|
| 764 | To use the options, add
|
---|
| 765 |
|
---|
| 766 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 21
|
---|
| 767 |
|
---|
| 768 | to your .pro file. The \c embed_manifest_dll option is enabled by default.
|
---|
| 769 |
|
---|
| 770 | You can find more information about manifest files and side-by-side
|
---|
| 771 | assemblies at the
|
---|
| 772 | \l {http://msdn.microsoft.com/en-us/library/aa376307.aspx}{MSDN website}.
|
---|
| 773 |
|
---|
| 774 | There are two ways to include the run time libraries: by bundling them
|
---|
| 775 | directly with your application or by installing them on the end-user's
|
---|
| 776 | system.
|
---|
| 777 |
|
---|
| 778 | To bundle the run time libraries with your application, copy the directory
|
---|
| 779 |
|
---|
| 780 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 22
|
---|
| 781 |
|
---|
| 782 | into the folder where your executable is, so that you are including a
|
---|
| 783 | \c Microsoft.VC80.CRT directory alongside your application's executable. If
|
---|
| 784 | you are bundling the runtimes and need to deploy plugins as well, you have
|
---|
| 785 | to remove the manifest from the plugins (embedded as a resource) by adding
|
---|
| 786 | the following line to the \c{.pro} file of the plugins you are compiling:
|
---|
| 787 |
|
---|
| 788 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 23
|
---|
| 789 |
|
---|
| 790 | \warning If you skip the step above, the plugins will not load on some
|
---|
| 791 | systems.
|
---|
| 792 |
|
---|
| 793 | To install the runtime libraries on the end-user's system, you need to
|
---|
| 794 | include the appropriate Visual C++ Redistributable Package (VCRedist)
|
---|
| 795 | executable with your application and ensure that it is executed when the
|
---|
| 796 | user installs your application.
|
---|
| 797 |
|
---|
| 798 | For example, on an 32-bit x86-based system, you would include the
|
---|
| 799 | \l{http://www.microsoft.com/downloads/details.aspx?FamilyId=32BC1BEE-A3F9-4C13-9C99-220B62A191EE}{vcredist_x86.exe}
|
---|
| 800 | executable. The \l{http://www.microsoft.com/downloads/details.aspx?familyid=526BF4A7-44E6-4A91-B328-A4594ADB70E5}{vcredist_IA64.exe}
|
---|
| 801 | and \l{http://www.microsoft.com/downloads/details.aspx?familyid=90548130-4468-4BBC-9673-D6ACABD5D13B}{vcredist_x64.exe}
|
---|
| 802 | executables provide the appropriate libraries for the IA64 and 64-bit x86
|
---|
| 803 | architectures, respectively.
|
---|
| 804 |
|
---|
| 805 | \note The application you ship must be compiled with exactly the same
|
---|
| 806 | compiler version against the same C runtime version. This prevents
|
---|
| 807 | deploying errors caused by different versions of the C runtime libraries.
|
---|
| 808 |
|
---|
| 809 | \section2 Visual Studio 2008 And Manual Installs
|
---|
| 810 |
|
---|
| 811 | As well as the above details for VS 2005 and onwards, Visual Studio 2008
|
---|
| 812 | applications may have problems when deploying manually, say to a USB
|
---|
| 813 | stick.
|
---|
| 814 |
|
---|
| 815 | The recommended procedure is to configure Qt with the \c -plugin-manifests
|
---|
| 816 | option using the 'configure' tool. Then follow the \l {http://msdn.microsoft.com/en-us/library/ms235291(VS.80).aspx}{guidelines}
|
---|
| 817 | for manually deploying private assemblies.
|
---|
| 818 |
|
---|
| 819 | In brief the steps are
|
---|
| 820 |
|
---|
| 821 | \list 1
|
---|
| 822 |
|
---|
| 823 | \o create a folder structure on the development computer that will match the target USB stick directory structure, for example '\\app' and for your dlls, '\\app\\lib'.
|
---|
| 824 |
|
---|
| 825 | \o on the development computer, from the appropriate 'redist' folder copy over Microsoft.VC80.CRT and Microsoft.VC80.MFC to the directories '\\app' and '\\app\\lib' on the development PC.
|
---|
| 826 |
|
---|
| 827 | \o xcopy the \\app folder to the target USB stick.
|
---|
| 828 | \endlist
|
---|
| 829 |
|
---|
| 830 | Your application should now run. Also be aware that even with a service
|
---|
| 831 | pack installed the Windows DLLs that are linked to will be the defaults. See
|
---|
| 832 | the information on \l {http://msdn.microsoft.com/en-us/library/cc664727.aspx}{how to select the appropriate target DLLs}.
|
---|
| 833 |
|
---|
| 834 | \section1 Application Dependencies
|
---|
| 835 |
|
---|
| 836 | \section2 Additional Libraries
|
---|
| 837 |
|
---|
| 838 | Depending on configuration, compiler specific libraries must be
|
---|
| 839 | redistributed along with your application. You can check which
|
---|
| 840 | libraries your application is linking against by using the
|
---|
| 841 | \l{Dependency Walker} tool. All you need to do is to run it like
|
---|
| 842 | this:
|
---|
| 843 |
|
---|
| 844 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 24
|
---|
| 845 |
|
---|
| 846 | This will provide a list of the libraries that your application
|
---|
| 847 | depends on and other information.
|
---|
| 848 |
|
---|
| 849 | \image deployment-windows-depends.png
|
---|
| 850 |
|
---|
| 851 | When looking at the release build of the Plug & Paint executable
|
---|
| 852 | (\c plugandpaint.exe) with the \c depends tool, the tool lists the
|
---|
| 853 | following immediate dependencies to non-system libraries:
|
---|
| 854 |
|
---|
| 855 | \table 100%
|
---|
| 856 | \header
|
---|
| 857 | \o Qt
|
---|
| 858 | \o VC++ 6.0
|
---|
| 859 | \o VC++ 7.1 (2003)
|
---|
| 860 | \o VC++ 8.0 (2005)
|
---|
| 861 | \o MinGW
|
---|
| 862 | \row
|
---|
| 863 | \o \list
|
---|
| 864 | \o QTCORE4.DLL - The QtCore runtime
|
---|
| 865 | \o QTGUI4.DLL - The QtGui runtime
|
---|
| 866 | \endlist
|
---|
| 867 | \o \list
|
---|
| 868 | \o MSVCRT.DLL - The C runtime
|
---|
| 869 | \o MSVCP60.DLL - The C++ runtime (only when STL is installed)
|
---|
| 870 | \endlist
|
---|
| 871 | \o \list
|
---|
| 872 | \o MSVCR71.DLL - The C runtime
|
---|
| 873 | \o MSVCP71.DLL - The C++ runtime (only when STL is installed)
|
---|
| 874 | \endlist
|
---|
| 875 | \o \list
|
---|
| 876 | \o MSVCR80.DLL - The C runtime
|
---|
| 877 | \o MSVCP80.DLL - The C++ runtime (only when STL is installed)
|
---|
| 878 | \endlist
|
---|
| 879 | \o \list
|
---|
| 880 | \o MINGWM10.DLL - The MinGW run-time
|
---|
| 881 | \endlist
|
---|
| 882 | \endtable
|
---|
| 883 |
|
---|
| 884 | When looking at the plugin DLLs the exact same dependencies
|
---|
| 885 | are listed.
|
---|
| 886 |
|
---|
| 887 | \section2 Qt Plugins
|
---|
| 888 |
|
---|
| 889 | Your application may also depend on one or more Qt plugins, such
|
---|
| 890 | as the JPEG image format plugin or a SQL driver plugin. Be sure
|
---|
| 891 | to distribute any Qt plugins that you need with your application,
|
---|
| 892 | and note that each type of plugin should be located within a
|
---|
| 893 | specific subdirectory (such as \c imageformats or \c sqldrivers)
|
---|
| 894 | within your distribution directory, as described below.
|
---|
| 895 |
|
---|
| 896 | \note If you are deploying an application that uses QtWebKit to display
|
---|
| 897 | HTML pages from the World Wide Web, you should include all text codec
|
---|
| 898 | plugins to support as many HTML encodings possible.
|
---|
| 899 |
|
---|
| 900 | The search path for Qt plugins is hard-coded into the QtCore library.
|
---|
| 901 | By default, the plugins subdirectory of the Qt installation is the first
|
---|
| 902 | plugin search path. However, pre-determined paths like the default one
|
---|
| 903 | have certain disadvantages. For example, they may not exist on the target
|
---|
| 904 | machine. For that reason, you need to examine various alternatives to make
|
---|
| 905 | sure that the Qt plugins are found:
|
---|
| 906 |
|
---|
| 907 | \list
|
---|
| 908 |
|
---|
| 909 | \o \l{qt-conf.html}{Using \c qt.conf}. This approach is the recommended
|
---|
| 910 | if you have executables in different places sharing the same plugins.
|
---|
| 911 |
|
---|
| 912 | \o Using QApplication::addLibraryPath() or
|
---|
| 913 | QApplication::setLibraryPaths(). This approach is recommended if you only
|
---|
| 914 | have one executable that will use the plugin.
|
---|
| 915 |
|
---|
| 916 | \o Using a third party installation utility to change the
|
---|
| 917 | hard-coded paths in the QtCore library.
|
---|
| 918 |
|
---|
| 919 | \endlist
|
---|
| 920 |
|
---|
| 921 | If you add a custom path using QApplication::addLibraryPath it could
|
---|
| 922 | look like this:
|
---|
| 923 |
|
---|
| 924 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 54
|
---|
| 925 |
|
---|
| 926 | Then qApp->libraryPaths() would return something like this:
|
---|
| 927 |
|
---|
| 928 | "C:/customPath/plugins "
|
---|
| 929 | "C:/Qt/4.6.1/plugins"
|
---|
| 930 | "E:/myApplication/directory/"
|
---|
| 931 |
|
---|
| 932 | The executable will look for the plugins in these directories and
|
---|
| 933 | the same order as the QStringList returned by qApp->libraryPaths().
|
---|
| 934 | The newly added path is prepended to the qApp->libraryPaths() which
|
---|
| 935 | means that it will be searched through first. However, if you use
|
---|
| 936 | qApp->setLibraryPaths(), you will be able to determend which paths
|
---|
| 937 | and in which order they will be searched.
|
---|
| 938 |
|
---|
| 939 | The \l{How to Create Qt Plugins} document outlines the issues you
|
---|
| 940 | need to pay attention to when building and deploying plugins for
|
---|
| 941 | Qt applications.
|
---|
| 942 |
|
---|
| 943 | \section1 Related Third Party Resources
|
---|
| 944 |
|
---|
| 945 | \list
|
---|
| 946 | \o \l{http://silmor.de/29}{Cross compiling Qt/Win Apps on Linux} covers the
|
---|
| 947 | process of cross-compiling Windows applications on Linux.
|
---|
| 948 | \o \l{http://divided-mind.blogspot.com/2007/09/cross-compiling-qt4win-on-linux.html}
|
---|
| 949 | {Cross-compiling Qt4/Win on Linux} provides another Linux-to-Windows
|
---|
| 950 | cross-compilation guide.
|
---|
| 951 | \endlist
|
---|
| 952 | */
|
---|
| 953 |
|
---|
| 954 | /*!
|
---|
| 955 | \page deployment-mac.html
|
---|
| 956 | \contentspage Deploying Qt Applications
|
---|
| 957 |
|
---|
| 958 | \title Deploying an Application on Mac OS X
|
---|
| 959 |
|
---|
| 960 | Starting with version 4.5, Qt now includes a \l {macdeploy}{deployment tool}
|
---|
| 961 | that automates the prodecures described in this document.
|
---|
| 962 |
|
---|
| 963 | This documentation will describe how to create a bundle, and how
|
---|
| 964 | to make sure that the application will find the resources it needs
|
---|
| 965 | at run-time. We will demonstrate the procedures in terms of
|
---|
| 966 | deploying the \l {tools/plugandpaint}{Plug & Paint} application
|
---|
| 967 | that is provided in Qt's examples directory.
|
---|
| 968 |
|
---|
| 969 | \tableofcontents
|
---|
| 970 |
|
---|
| 971 | \section1 The Bundle
|
---|
| 972 |
|
---|
| 973 | On the Mac, a GUI application must be built and run from a
|
---|
| 974 | bundle. A bundle is a directory structure that appears as a single
|
---|
| 975 | entity when viewed in the Finder. A bundle for an application
|
---|
| 976 | typcially contains the executable and all the resources it
|
---|
| 977 | needs. See the image below:
|
---|
| 978 |
|
---|
| 979 | \image deployment-mac-bundlestructure.png
|
---|
| 980 |
|
---|
| 981 | The bundle provides many advantages to the user. One primary
|
---|
| 982 | advantage is that, since it is a single entity, it allows for
|
---|
| 983 | drag-and-drop installation. As a programmer you can access bundle
|
---|
| 984 | information in your own code. This is specific to Mac OS X and
|
---|
| 985 | beyond the scope of this document. More information about bundles
|
---|
| 986 | is available on \l
|
---|
| 987 | {http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/index.html}{Apple's Developer Website}.
|
---|
| 988 |
|
---|
| 989 | A Qt command line application on Mac OS X works similar to a
|
---|
| 990 | command line application on Unix and Windows. You probably don't
|
---|
| 991 | want to run it in a bundle: Add this to your application's .pro:
|
---|
| 992 |
|
---|
| 993 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 26
|
---|
| 994 |
|
---|
| 995 | This will tell \c qmake not to put the executable inside a
|
---|
| 996 | bundle. Please refer to the \l{Deploying an Application on
|
---|
| 997 | X11 Platforms}{X11 deployment documentation} for information about how
|
---|
| 998 | to deploy these "bundle-less" applications.
|
---|
| 999 |
|
---|
| 1000 | \section1 Xcode
|
---|
| 1001 |
|
---|
| 1002 | We will only concern ourselves with command-line tools here. While
|
---|
| 1003 | it is possible to use Xcode for this, Xcode has changed enough
|
---|
| 1004 | between each version that it makes it difficult to document it
|
---|
| 1005 | perfectly for each version. A future version of this document may
|
---|
| 1006 | include more information for using Xcode in the deployment
|
---|
| 1007 | process.
|
---|
| 1008 |
|
---|
| 1009 | \section1 Static Linking
|
---|
| 1010 |
|
---|
| 1011 | If you want to keep things simple by only having a few files to
|
---|
| 1012 | deploy, then you must build everything statically.
|
---|
| 1013 |
|
---|
| 1014 | \section2 Building Qt Statically
|
---|
| 1015 |
|
---|
| 1016 | Start by installing a static version of the Qt library. Remember
|
---|
| 1017 | that you will not be able to use plugins and you must build in all
|
---|
| 1018 | the image formats, SQL drivers, etc..
|
---|
| 1019 |
|
---|
| 1020 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 27
|
---|
| 1021 |
|
---|
| 1022 | You can check the various options that are available by running \c
|
---|
| 1023 | configure -help.
|
---|
| 1024 |
|
---|
| 1025 | \section2 Linking the Application to the Static Version of Qt
|
---|
| 1026 |
|
---|
| 1027 | Once Qt is built statically, the next step is to regenerate the
|
---|
| 1028 | makefile and rebuild the application. First, we must go into the
|
---|
| 1029 | directory that contains the application:
|
---|
| 1030 |
|
---|
| 1031 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 28
|
---|
| 1032 |
|
---|
| 1033 | Now run \c qmake to create a new makefile for the application, and do
|
---|
| 1034 | a clean build to create the statically linked executable:
|
---|
| 1035 |
|
---|
| 1036 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 29
|
---|
| 1037 |
|
---|
| 1038 | You probably want to link against the release libraries, and you
|
---|
| 1039 | can specify this when invoking \c qmake. If you have Xcode Tools
|
---|
| 1040 | 1.5 or higher installed, you may want to take advantage of "dead
|
---|
| 1041 | code stripping" to reduce the size of your binary even more. You
|
---|
| 1042 | can do this by passing \c {LIBS+= -dead_strip} to \c qmake in
|
---|
| 1043 | addition to the \c {-config release} parameter. This doesn't have
|
---|
| 1044 | as large an effect if you are using GCC 4, since Qt will then have
|
---|
| 1045 | function visibility hints built-in, but if you use GCC 3.3, it
|
---|
| 1046 | could make a difference.
|
---|
| 1047 |
|
---|
| 1048 | Now, provided that everything compiled and linked without any
|
---|
| 1049 | errors, we should have a \c plugandpaint.app bundle that is ready
|
---|
| 1050 | for deployment. One easy way to check that the application really
|
---|
| 1051 | can be run stand-alone is to copy the bundle to a machine that
|
---|
| 1052 | doesn't have Qt or any Qt applications installed, and run the
|
---|
| 1053 | application on that machine.
|
---|
| 1054 |
|
---|
| 1055 | You can check what other libraries your application links to using
|
---|
| 1056 | the \c otool:
|
---|
| 1057 |
|
---|
| 1058 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 30
|
---|
| 1059 |
|
---|
| 1060 | Here is what the output looks like for the static \l
|
---|
| 1061 | {tools/plugandpaint}{Plug & Paint}:
|
---|
| 1062 |
|
---|
| 1063 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 31
|
---|
| 1064 |
|
---|
| 1065 | For more information, see the \l {Application Dependencies}
|
---|
| 1066 | section.
|
---|
| 1067 |
|
---|
| 1068 | If you see \e Qt libraries in the output, it probably
|
---|
| 1069 | means that you have both dynamic and static Qt libraries installed
|
---|
| 1070 | on your machine. The linker will always choose dynamic over
|
---|
| 1071 | static. There are two solutions: Either move your Qt dynamic
|
---|
| 1072 | libraries (\c .dylibs) away to another directory while you link
|
---|
| 1073 | the application and then move them back, or edit the \c Makefile
|
---|
| 1074 | and replace link lines for the Qt libraries with the absolute path
|
---|
| 1075 | to the static libraries. For example, replace
|
---|
| 1076 |
|
---|
| 1077 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 32
|
---|
| 1078 |
|
---|
| 1079 | with
|
---|
| 1080 |
|
---|
| 1081 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 33
|
---|
| 1082 |
|
---|
| 1083 | The \l {tools/plugandpaint}{Plug & Paint} example consists of
|
---|
| 1084 | several components: The core application (\l
|
---|
| 1085 | {tools/plugandpaint}{Plug & Paint}), and the \l
|
---|
| 1086 | {tools/plugandpaintplugins/basictools}{Basic Tools} and \l
|
---|
| 1087 | {tools/plugandpaintplugins/extrafilters}{Extra Filters}
|
---|
| 1088 | plugins. Since we cannot deploy plugins using the static linking
|
---|
| 1089 | approach, the bundle we have prepared so far is incomplete. The
|
---|
| 1090 | application will run, but the functionality will be disabled due
|
---|
| 1091 | to the missing plugins. To deploy plugin-based applications we
|
---|
| 1092 | should use the framework approach.
|
---|
| 1093 |
|
---|
| 1094 | \section1 Frameworks
|
---|
| 1095 |
|
---|
| 1096 | We have two challenges when deploying the \l
|
---|
| 1097 | {tools/plugandpaint}{Plug & Paint} application using frameworks:
|
---|
| 1098 | The Qt runtime has to be correctly redistributed along with the
|
---|
| 1099 | application bundle, and the plugins have to be installed in the
|
---|
| 1100 | correct location so that the application can find them.
|
---|
| 1101 |
|
---|
| 1102 | When distributing Qt with your application using frameworks, you
|
---|
| 1103 | have two options: You can either distribute Qt as a private
|
---|
| 1104 | framework within your application bundle, or you can distribute Qt
|
---|
| 1105 | as a standard framework (alternatively use the Qt frameworks in
|
---|
| 1106 | the installed binary). These two approaches are essentially the
|
---|
| 1107 | same. The latter option is good if you have many Qt applications
|
---|
| 1108 | and you would prefer to save memory. The former is good if you
|
---|
| 1109 | have Qt built in a special way, or want to make sure the framework
|
---|
| 1110 | is there. It just comes down to where you place the Qt frameworks.
|
---|
| 1111 |
|
---|
| 1112 | \section2 Building Qt as Frameworks
|
---|
| 1113 |
|
---|
| 1114 | We assume that you already have installed Qt as frameworks, which
|
---|
| 1115 | is the default when installing Qt, in the /path/to/Qt
|
---|
| 1116 | directory. For more information on how to build Qt, see the \l
|
---|
| 1117 | Installation documentation.
|
---|
| 1118 |
|
---|
| 1119 | When installing, the identification name of the frameworks will
|
---|
| 1120 | also be set. The identification name is what the dynamic linker
|
---|
| 1121 | (\c dyld) uses to find the libraries for your application.
|
---|
| 1122 |
|
---|
| 1123 | \section2 Linking the Application to Qt as Frameworks
|
---|
| 1124 |
|
---|
| 1125 | After ensuring that Qt is built as frameworks, we can build the \l
|
---|
| 1126 | {tools/plugandpaint}{Plug & Paint} application. First, we must go
|
---|
| 1127 | into the directory that contains the application:
|
---|
| 1128 |
|
---|
| 1129 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 34
|
---|
| 1130 |
|
---|
| 1131 | Now run qmake to create a new makefile for the application, and do
|
---|
| 1132 | a clean build to create the dynamically linked executable:
|
---|
| 1133 |
|
---|
| 1134 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 35
|
---|
| 1135 |
|
---|
| 1136 | This builds the core application, the following will build the
|
---|
| 1137 | plugins:
|
---|
| 1138 |
|
---|
| 1139 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 36
|
---|
| 1140 |
|
---|
| 1141 | Now run the \c otool for the Qt frameworks, for example Qt Gui:
|
---|
| 1142 |
|
---|
| 1143 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 37
|
---|
| 1144 |
|
---|
| 1145 | You will get the following output:
|
---|
| 1146 |
|
---|
| 1147 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 38
|
---|
| 1148 |
|
---|
| 1149 | For the Qt frameworks, the first line (i.e. \c
|
---|
| 1150 | {path/to/Qt/lib/QtGui.framework/Versions/4/QtGui (compatibility
|
---|
| 1151 | version 4.0.0, current version 4.0.1)}) becomes the framework's
|
---|
| 1152 | identification name which is used by the dynamic linker (\c dyld).
|
---|
| 1153 |
|
---|
| 1154 | But when you are deploying the application, your users may not
|
---|
| 1155 | have the Qt frameworks installed in the specified location. For
|
---|
| 1156 | that reason, you must either provide the frameworks in an agreed
|
---|
| 1157 | upon location, or store the frameworks in the bundle itself.
|
---|
| 1158 | Regardless of which solution you choose, you must make sure that
|
---|
| 1159 | the frameworks return the proper identification name for
|
---|
| 1160 | themselves, and that the application will look for these
|
---|
| 1161 | names. Luckily we can control this with the \c install_name_tool
|
---|
| 1162 | command-line tool.
|
---|
| 1163 |
|
---|
| 1164 | The \c install_name_tool works in two modes, \c -id and \c
|
---|
| 1165 | -change. The \c -id mode is for libraries and frameworks, and
|
---|
| 1166 | allows us to specify a new identification name. We use the \c
|
---|
| 1167 | -change mode to change the paths in the application.
|
---|
| 1168 |
|
---|
| 1169 | Let's test this out by copying the Qt frameworks into the Plug &
|
---|
| 1170 | Paint bundle. Looking at \c otool's output for the bundle, we can
|
---|
| 1171 | see that we must copy both the QtCore and QtGui frameworks into
|
---|
| 1172 | the bundle. We will assume that we are in the directory where we
|
---|
| 1173 | built the bundle.
|
---|
| 1174 |
|
---|
| 1175 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 39
|
---|
| 1176 |
|
---|
| 1177 | First we create a \c Frameworks directory inside the bundle. This
|
---|
| 1178 | follows the Mac OS X application convention. We then copy the
|
---|
| 1179 | frameworks into the new directory. Since frameworks contain
|
---|
| 1180 | symbolic links, and we want to preserve them, we use the \c -R
|
---|
| 1181 | option.
|
---|
| 1182 |
|
---|
| 1183 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 40
|
---|
| 1184 |
|
---|
| 1185 | Then we run \c install_name_tool to set the identification names
|
---|
| 1186 | for the frameworks. The first argument after \c -id is the new
|
---|
| 1187 | name, and the second argument is the framework which
|
---|
| 1188 | identification we wish to change. The text \c @executable_path is
|
---|
| 1189 | a special \c dyld variable telling \c dyld to start looking where
|
---|
| 1190 | the executable is located. The new names specifies that these
|
---|
| 1191 | frameworks will be located "one directory up and over" in the \c
|
---|
| 1192 | Frameworks directory.
|
---|
| 1193 |
|
---|
| 1194 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 41
|
---|
| 1195 |
|
---|
| 1196 | Now, the dynamic linker knows where to look for QtCore and
|
---|
| 1197 | QtGui. Then we must make the application aware of the library
|
---|
| 1198 | locations as well using \c install_name_tool's \c -change mode.
|
---|
| 1199 | This basically comes down to string replacement, to match the
|
---|
| 1200 | identification names that we set for the frameworks.
|
---|
| 1201 |
|
---|
| 1202 | Finally, since the QtGui framework depends on QtCore, we must
|
---|
| 1203 | remember to change the reference for QtGui:
|
---|
| 1204 |
|
---|
| 1205 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 42
|
---|
| 1206 |
|
---|
| 1207 | After all this we can run \c otool again and see that the
|
---|
| 1208 | application will look in the right locations.
|
---|
| 1209 |
|
---|
| 1210 | Of course, the thing that makes the \l {tools/plugandpaint}{Plug &
|
---|
| 1211 | Paint} example interesting are its plugins. The basic steps we
|
---|
| 1212 | need to follow with plugins are:
|
---|
| 1213 |
|
---|
| 1214 | \list
|
---|
| 1215 | \o Put the plugins inside the bundle
|
---|
| 1216 | \o Make sure that the plugins use the correct library using the
|
---|
| 1217 | \c install_name_tool
|
---|
| 1218 | \o Make sure that the application knows where to get the plugins
|
---|
| 1219 | \endlist
|
---|
| 1220 |
|
---|
| 1221 | While we can put the plugins anywhere we want in the bundle, the
|
---|
| 1222 | best location to put them is under Contents/Plugins. When we built
|
---|
| 1223 | the Plug & Paint plugins, the \c DESTDIR variable in their \c .pro
|
---|
| 1224 | file put the plugins' \c .dylib files in a \c plugins subdirectory
|
---|
| 1225 | in the \c plugandpaint directory. So, in this example, all we need
|
---|
| 1226 | to do is move this directory:
|
---|
| 1227 |
|
---|
| 1228 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 43
|
---|
| 1229 |
|
---|
| 1230 | If we run \c otool on for example the \l
|
---|
| 1231 | {tools/plugandpaintplugins/basictools}{Basic Tools} plugin's \c
|
---|
| 1232 | .dylib file we get the following information.
|
---|
| 1233 |
|
---|
| 1234 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 44
|
---|
| 1235 |
|
---|
| 1236 | Then we can see that the plugin links to the Qt frameworks it was
|
---|
| 1237 | built against. Since we want the plugins to use the framework in
|
---|
| 1238 | the application bundle we change them the same way as we did for
|
---|
| 1239 | the application. For example for the Basic Tools plugin:
|
---|
| 1240 |
|
---|
| 1241 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 45
|
---|
| 1242 |
|
---|
| 1243 |
|
---|
| 1244 | We must also modify the code in \c
|
---|
| 1245 | tools/plugandpaint/mainwindow.cpp to \l {QDir::cdUp()}{cdUp()} one
|
---|
| 1246 | directory since the plugins live in the bundle. Add the following
|
---|
| 1247 | code to the \c mainwindow.cpp file:
|
---|
| 1248 |
|
---|
| 1249 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 46
|
---|
| 1250 |
|
---|
| 1251 | \table
|
---|
| 1252 | \row
|
---|
| 1253 | \o \inlineimage deployment-mac-application.png
|
---|
| 1254 | \o
|
---|
| 1255 | The additional code in \c tools/plugandpaint/mainwindow.cpp also
|
---|
| 1256 | enables us to view the plugins in the Finder, as shown to the left.
|
---|
| 1257 |
|
---|
| 1258 | We can also add plugins extending Qt, for example adding SQL
|
---|
| 1259 | drivers or image formats. We just need to follow the directory
|
---|
| 1260 | structure outlined in plugin documentation, and make sure they are
|
---|
| 1261 | included in the QCoreApplication::libraryPaths(). Let's quickly do
|
---|
| 1262 | this with the image formats, following the approach from above.
|
---|
| 1263 |
|
---|
| 1264 | Copy Qt's image format plugins into the bundle:
|
---|
| 1265 |
|
---|
| 1266 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 47
|
---|
| 1267 |
|
---|
| 1268 | Use \c install_name_tool to link the plugins to the frameworks in
|
---|
| 1269 | the bundle:
|
---|
| 1270 |
|
---|
| 1271 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 48
|
---|
| 1272 |
|
---|
| 1273 | Then we update the source code in \c tools/plugandpaint/main.cpp
|
---|
| 1274 | to look for the new plugins. After constructing the
|
---|
| 1275 | QApplication, we add the following code:
|
---|
| 1276 |
|
---|
| 1277 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 49
|
---|
| 1278 |
|
---|
| 1279 | First, we tell the application to only look for plugins in this
|
---|
| 1280 | directory. In our case, this is what we want since we only want to
|
---|
| 1281 | look for the plugins that we distribute with the bundle. If we
|
---|
| 1282 | were part of a bigger Qt installation we could have used
|
---|
| 1283 | QCoreApplication::addLibraryPath() instead.
|
---|
| 1284 |
|
---|
| 1285 | \endtable
|
---|
| 1286 |
|
---|
| 1287 | \warning When deploying plugins, and thus make changes to the
|
---|
| 1288 | source code, the default identification names are reset when
|
---|
| 1289 | rebuilding the application, and you must repeat the process of
|
---|
| 1290 | making your application link to the Qt frameworks in the bundle
|
---|
| 1291 | using \c install_name_tool.
|
---|
| 1292 |
|
---|
| 1293 | Now you should be able to move the application to another Mac OS X
|
---|
| 1294 | machine and run it without Qt installed. Alternatively, you can
|
---|
| 1295 | move your frameworks that live outside of the bundle to another
|
---|
| 1296 | directory and see if the application still runs.
|
---|
| 1297 |
|
---|
| 1298 | If you store the frameworks in another location than in the
|
---|
| 1299 | bundle, the technique of linking your application is similar; you
|
---|
| 1300 | must make sure that the application and the frameworks agree where
|
---|
| 1301 | to be looking for the Qt libraries as well as the plugins.
|
---|
| 1302 |
|
---|
| 1303 | \section2 Creating the Application Package
|
---|
| 1304 |
|
---|
| 1305 | When you are done linking your application to Qt, either
|
---|
| 1306 | statically or as frameworks, the application is ready to be
|
---|
| 1307 | distributed. Apple provides a fair bit of information about how to
|
---|
| 1308 | do this and instead of repeating it here, we recommend that you
|
---|
| 1309 | consult their \l
|
---|
| 1310 | {http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/index.html}{software delivery}
|
---|
| 1311 | documentation.
|
---|
| 1312 |
|
---|
| 1313 | Although the process of deploying an application do have some
|
---|
| 1314 | pitfalls, once you know the various issues you can easily create
|
---|
| 1315 | packages that all your Mac OS X users will enjoy.
|
---|
| 1316 |
|
---|
| 1317 | \section1 Application Dependencies
|
---|
| 1318 |
|
---|
| 1319 | \section2 Qt Plugins
|
---|
| 1320 |
|
---|
| 1321 | Your application may also depend on one or more Qt plugins, such
|
---|
| 1322 | as the JPEG image format plugin or a SQL driver plugin. Be sure
|
---|
| 1323 | to distribute any Qt plugins that you need with your application,
|
---|
| 1324 | and note that each type of plugin should be located within a
|
---|
| 1325 | specific subdirectory (such as \c imageformats or \c sqldrivers)
|
---|
| 1326 | within your distribution directory, as described below.
|
---|
| 1327 |
|
---|
| 1328 | \note If you are deploying an application that uses QtWebKit to display
|
---|
| 1329 | HTML pages from the World Wide Web, you should include all text codec
|
---|
| 1330 | plugins to support as many HTML encodings possible.
|
---|
| 1331 |
|
---|
| 1332 | The search path for Qt plugins (as well as a few other paths) is
|
---|
| 1333 | hard-coded into the QtCore library. By default, the first plugin
|
---|
| 1334 | search path will be hard-coded as \c /path/to/Qt/plugins. But
|
---|
| 1335 | using pre-determined paths has certain disadvantages. For example,
|
---|
| 1336 | they may not exist on the target machine. For that reason you need
|
---|
| 1337 | to examine various alternatives to make sure that the Qt plugins
|
---|
| 1338 | are found:
|
---|
| 1339 |
|
---|
| 1340 | \list
|
---|
| 1341 |
|
---|
| 1342 | \o \l{qt-conf.html}{Using \c qt.conf}. This is the recommended
|
---|
| 1343 | approach since it provides the most flexibility.
|
---|
| 1344 |
|
---|
| 1345 | \o Using QApplication::addLibraryPath() or
|
---|
| 1346 | QApplication::setLibraryPaths().
|
---|
| 1347 |
|
---|
| 1348 | \o Using a third party installation utility to change the
|
---|
| 1349 | hard-coded paths in the QtCore library.
|
---|
| 1350 |
|
---|
| 1351 | \endlist
|
---|
| 1352 |
|
---|
| 1353 | The \l{How to Create Qt Plugins} document outlines the issues you
|
---|
| 1354 | need to pay attention to when building and deploying plugins for
|
---|
| 1355 | Qt applications.
|
---|
| 1356 |
|
---|
| 1357 | \section2 Additional Libraries
|
---|
| 1358 |
|
---|
| 1359 | You can check which libraries your application is linking against
|
---|
| 1360 | by using the \c otool tool. To use \c otool, all you need to do is
|
---|
| 1361 | to run it like this:
|
---|
| 1362 |
|
---|
| 1363 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 50
|
---|
| 1364 |
|
---|
| 1365 | Unlike the deployment processes on \l {Deploying an Application on
|
---|
| 1366 | X11 Platforms}{X11} and \l {Deploying an Application on
|
---|
| 1367 | Windows}{Windows}, compiler specific libraries rarely have to
|
---|
| 1368 | be redistributed along with your application. But since Qt can be
|
---|
| 1369 | configured, built, and installed in several ways on Mac OS X,
|
---|
| 1370 | there are also several ways to deploy applications. Typically your
|
---|
| 1371 | goals help determine how you are going to deploy the
|
---|
| 1372 | application. The last sections describe a couple of things to keep
|
---|
| 1373 | in mind when you are deploying your application.
|
---|
| 1374 |
|
---|
| 1375 | \section2 Mac OS X Version Dependencies
|
---|
| 1376 |
|
---|
| 1377 | Qt 4.2 has been designed to be built and deployed on Mac OS X 10.3
|
---|
| 1378 | up until the current version as of this writing, Mac OS X 10.4 and
|
---|
| 1379 | all their minor releases. Qt achieves this by using "weak
|
---|
| 1380 | linking." This means that Qt tests if a function added in newer
|
---|
| 1381 | versions of Mac OS X is available on the computer it is running on
|
---|
| 1382 | before it uses it. This results in getting access to newer
|
---|
| 1383 | features when running on newer versions of OS X while still
|
---|
| 1384 | remaining compatible on older versions.
|
---|
| 1385 |
|
---|
| 1386 | For more information about cross development issues on Mac OS X,
|
---|
| 1387 | see \l
|
---|
| 1388 | {http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_development/index.html}{Apple's Developer Website}.
|
---|
| 1389 |
|
---|
| 1390 | Since the linker is set to be compatible with all OS X version, you have to
|
---|
| 1391 | change the \c MACOSX_DEPLOYMENT_TARGET environment variable to get weak
|
---|
| 1392 | linking to work for your application. You can add:
|
---|
| 1393 |
|
---|
| 1394 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 51
|
---|
| 1395 |
|
---|
| 1396 | to your .pro file and qmake will take care of this for you.
|
---|
| 1397 |
|
---|
| 1398 | However, there is a bit of a wrinkle to keep in mind when your are
|
---|
| 1399 | deploying. Mac OS X 10.4 ("Tiger") ships GCC 4.0 as its default
|
---|
| 1400 | compiler. This is also the GCC compiler we use for building the
|
---|
| 1401 | binary Qt package. If you use GCC 4.0 to build your application,
|
---|
| 1402 | it will link against a dynamic libstdc++ that is only available on
|
---|
| 1403 | Mac OS X 10.4 and Mac OS X 10.3.9. The application will refuse to
|
---|
| 1404 | run on older versions of the operating system.
|
---|
| 1405 |
|
---|
| 1406 | For more information about C++ runtime environment, see \l
|
---|
| 1407 | {http://developer.apple.com/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/index.html}{Apple's Developer Website}
|
---|
| 1408 |
|
---|
| 1409 | If you want to deploy to versions of Mac OS X earlier than 10.3.9,
|
---|
| 1410 | you must build with GCC 3.3 which is the default on Mac OS X
|
---|
| 1411 | 10.3. GCC 3.3 is also available on the Mac OS X 10.4 "Xcode Tools"
|
---|
| 1412 | CD and as a download for earlier versions of Mac OS X from Apple
|
---|
| 1413 | (\l {https://connect.apple.com/}{connect.apple.com}). You can use
|
---|
| 1414 | Apple's \c gcc_select(1) command line tool to switch the default
|
---|
| 1415 | complier on your system.
|
---|
| 1416 |
|
---|
| 1417 | \section3 Deploying Phonon Applications on Mac OS X
|
---|
| 1418 |
|
---|
| 1419 | \list
|
---|
| 1420 | \o If you build your Phonon application on Tiger, it will work on
|
---|
| 1421 | Tiger, Leopard and Panther.
|
---|
| 1422 | \o If you build your application on Leopard, it will \bold not work
|
---|
| 1423 | on Panther unless you rename the libraries with the following command
|
---|
| 1424 | after you have built your application:
|
---|
| 1425 |
|
---|
| 1426 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 51a
|
---|
| 1427 |
|
---|
| 1428 | This command must be invoked in the directory where
|
---|
| 1429 | \c{libphonon_qt7.dylib} is located, usually in
|
---|
| 1430 | \c{yourapp.app/Contents/plugins/phonon_backend/}.
|
---|
| 1431 | \o The \l {macdeploy}{deployment tool} will perform this step for you.
|
---|
| 1432 |
|
---|
| 1433 | \o If you are using Leopard, but would like to build your application
|
---|
| 1434 | against Tiger, you can use:
|
---|
| 1435 |
|
---|
| 1436 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 51b
|
---|
| 1437 | \endlist
|
---|
| 1438 |
|
---|
| 1439 | \section2 Architecture Dependencies
|
---|
| 1440 |
|
---|
| 1441 | The Qt for Mac OS X libraries, tools, and examples can be built "universal"
|
---|
| 1442 | (i.e. they run natively on both Intel and PowerPC machines). This
|
---|
| 1443 | is accomplished by passing \c -universal on the \c configure line
|
---|
| 1444 | of the source package, and requires that you use GCC 4.0.x. On
|
---|
| 1445 | PowerPC hardware you will need to pass the universal SDK as a
|
---|
| 1446 | command line argument to the Qt configure command. For example:
|
---|
| 1447 |
|
---|
| 1448 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 52
|
---|
| 1449 |
|
---|
| 1450 | From 4.1.1 the Qt binary package is already universal.
|
---|
| 1451 |
|
---|
| 1452 | If you want to create a binary that runs on older versions of
|
---|
| 1453 | PowerPC and x86, it is possible to build Qt for the PowerPC using
|
---|
| 1454 | GCC 3.3, and for x86 one using GCC 4.0, and use Apple's \c lipo(1)
|
---|
| 1455 | tool to stitch them together. This is beyond the scope of this
|
---|
| 1456 | document and is not something we have tried, but Apple documents
|
---|
| 1457 | it on their \l
|
---|
| 1458 | {http://developer.apple.com/documentation/}{developer website}.
|
---|
| 1459 |
|
---|
| 1460 | Once you have a universal Qt, \a qmake will generate makefiles
|
---|
| 1461 | that will build for its host architecture by default. If you want
|
---|
| 1462 | to build for a specific architecture, you can control this with
|
---|
| 1463 | the \c CONFIG line in your \c .pro file. Use \c CONFIG+=ppc for
|
---|
| 1464 | PowerPC, and \c CONFIG+=x86 for x86. If you desire both, simply
|
---|
| 1465 | add both to the \c CONFIG line. PowerPC users also need an
|
---|
| 1466 | SDK. For example:
|
---|
| 1467 |
|
---|
| 1468 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 53
|
---|
| 1469 |
|
---|
| 1470 | Besides \c lipo, you can also check your binaries with the \c file(1)
|
---|
| 1471 | command line tool or the Finder.
|
---|
| 1472 |
|
---|
| 1473 | \section1 The Mac Deployment Tool
|
---|
| 1474 | \target macdeploy
|
---|
| 1475 | The Mac deployment tool can be found in QTDIR/bin/macdeployqt. It is
|
---|
| 1476 | designed to automate the process of creating a deployable
|
---|
| 1477 | application bundle that contains the Qt libraries as private
|
---|
| 1478 | frameworks.
|
---|
| 1479 |
|
---|
| 1480 | The mac deployment tool also deploys the Qt plugins, according
|
---|
| 1481 | to the following rules:
|
---|
| 1482 | \list
|
---|
| 1483 | \o Debug versions of the plugins are not deployed.
|
---|
| 1484 | \o The designer plugins are not deployed.
|
---|
| 1485 | \o The Image format plugins are always deployed.
|
---|
| 1486 | \o SQL driver plugins are deployed if the application uses the QtSql module.
|
---|
| 1487 | \o Script plugins are deployed if the application uses the QtScript module.
|
---|
| 1488 | \o The Phonon backend plugin is deployed if the application uses the \l{Phonon Module} {Phonon} module.
|
---|
| 1489 | \o The svg icon plugin is deployed if the application uses the QtSvg module.
|
---|
| 1490 | \o The accessibility plugin is always deployed.
|
---|
| 1491 | \o Accessibility for Qt3Support is deployed if the application uses the Qt3Support module.
|
---|
| 1492 | \endlist
|
---|
| 1493 |
|
---|
| 1494 | \note If you want a 3rd party library to be included in your
|
---|
| 1495 | application bundle, then you must add an excplicit lib entry for
|
---|
| 1496 | that library to your application's .pro file. Otherwise, the
|
---|
| 1497 | \c macdeployqt tool will not copy the 3rd party .dylib into the
|
---|
| 1498 | bundle.
|
---|
| 1499 |
|
---|
| 1500 | \c macdeployqt supports the following options:
|
---|
| 1501 | \list
|
---|
| 1502 | \o -no-plugins: Skip plugin deployment
|
---|
| 1503 | \o -dmg : Create a .dmg disk image
|
---|
| 1504 | \o -no-strip : Don't run 'strip' on the binaries
|
---|
| 1505 | \endlist
|
---|
| 1506 | */
|
---|
| 1507 |
|
---|
| 1508 | /*!
|
---|
| 1509 | \page deployment-symbian.html
|
---|
| 1510 | \contentspage Deploying Qt Applications
|
---|
| 1511 |
|
---|
| 1512 | \title Deploying an Application on the Symbian platform
|
---|
| 1513 |
|
---|
| 1514 | Applications are deployed to Symbian devices in signed \c .sis package files.
|
---|
| 1515 | The \c .sis file content is controlled with \c .pkg files. The \c .pkg file contains a set
|
---|
| 1516 | of instructions used by tools to produce a \c .sis file. \c qmake generates a
|
---|
| 1517 | default \c .pkg file for your project. The \c .pkg file generated by \c qmake is typically
|
---|
| 1518 | fully functional for testing purposes but when planning to deliver your application
|
---|
| 1519 | to end-users some changes are needed. This document describes what changes are
|
---|
| 1520 | typically needed and how to implement them.
|
---|
| 1521 |
|
---|
| 1522 | \section1 Static Linking
|
---|
| 1523 |
|
---|
| 1524 | Qt for the Symbian platform does currently not support static linking of
|
---|
| 1525 | Qt libraries.
|
---|
| 1526 |
|
---|
| 1527 | \section1 Shared Libraries
|
---|
| 1528 |
|
---|
| 1529 | When deploying the application using the shared libraries approach we must ensure that the
|
---|
| 1530 | Qt runtime is correctly redistributed along with the application executable,
|
---|
| 1531 | and also that all Qt dependencies are redistributed along with the application.
|
---|
| 1532 |
|
---|
| 1533 | We will demonstrate these procedures in terms of deploying the \l {widgets/wiggly}{Wiggly}
|
---|
| 1534 | application that is provided in Qt's examples directory.
|
---|
| 1535 |
|
---|
| 1536 | \section2 Building Qt as a Shared Library
|
---|
| 1537 |
|
---|
| 1538 | We assume that you already have installed Qt as a shared library,
|
---|
| 1539 | in the \c C:\path\to\Qt directory which is the default when installing Qt for Symbian.
|
---|
| 1540 | For more information on how to build Qt, see the \l {Installation} documentation.
|
---|
| 1541 |
|
---|
| 1542 | \section1 Shared Libraries
|
---|
| 1543 |
|
---|
| 1544 | After ensuring that Qt is built as a shared library, we can build
|
---|
| 1545 | the \l {widgets/wiggly}{Wiggly} application. First, we
|
---|
| 1546 | must go into the directory that contains the application:
|
---|
| 1547 |
|
---|
| 1548 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 55
|
---|
| 1549 |
|
---|
| 1550 | To prepare the application for deployment we must ensure that the \c .pkg file generated by
|
---|
| 1551 | \c qmake contains the relevant vendor information and embeds the necessary
|
---|
| 1552 | dependencies to the application deployment file (\c .sis). The content of the generated \c .pkg
|
---|
| 1553 | file can be controlled with the Symbian specific \c qmake \l DEPLOYMENT keyword extensions.
|
---|
| 1554 |
|
---|
| 1555 | First, we will change the vendor statement to something more meaningful. The application
|
---|
| 1556 | vendor is visible to end-user during the installation.
|
---|
| 1557 |
|
---|
| 1558 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 56
|
---|
| 1559 |
|
---|
| 1560 | Second we will tell the Symbian application installer that this application supports
|
---|
| 1561 | only S60 5.0 based devices:
|
---|
| 1562 |
|
---|
| 1563 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 57
|
---|
| 1564 |
|
---|
| 1565 | You can find a list of platform and device indentification codes from
|
---|
| 1566 | \l {http://wiki.forum.nokia.com/index.php/S60_Platform_and_device_identification_codes}{Forum Nokia Wiki}.
|
---|
| 1567 | By default \c .pkg file generated by \c qmake adds support for all
|
---|
| 1568 | S60 3rd edition FP1, S60 3rd edition FP2 and S60 5th edition devices.
|
---|
| 1569 |
|
---|
| 1570 | As a last step we will embed the \c qt_installer.sis file to the Wiggly
|
---|
| 1571 | deployment file:
|
---|
| 1572 |
|
---|
| 1573 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 58
|
---|
| 1574 |
|
---|
| 1575 | When \c qt_installer.sis is embedded to the application deployment file, the
|
---|
| 1576 | end-user does not need to download and install all dependencies separately.
|
---|
| 1577 | The drawback of \c .sis embedding is that the application \c .sis file size becomes
|
---|
| 1578 | big. To address these problems Forum Nokia is planning to release a smart installer
|
---|
| 1579 | which will take care of downloading and installing the necessary dependencies
|
---|
| 1580 | over-the-air. The expected availability of smart installer is 1Q 2010.
|
---|
| 1581 |
|
---|
| 1582 | Now we are ready to compile the application and create the application
|
---|
| 1583 | deployment file. Run \c qmake to create Symbian specific makefiles, resources (\.rss)
|
---|
| 1584 | and deployment packaging files (\c .pkg). And do build to create the
|
---|
| 1585 | application binaries and resources.
|
---|
| 1586 |
|
---|
| 1587 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 59
|
---|
| 1588 |
|
---|
| 1589 | If everything compiled and linked without any errors, we are now ready to create
|
---|
| 1590 | an application installation file:
|
---|
| 1591 |
|
---|
| 1592 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 60
|
---|
| 1593 |
|
---|
| 1594 | If all binaries and dependencies were found, we should now have a self-signed
|
---|
| 1595 | \c wiggly_release-gcce.sis ready to be installed on a device. For more information
|
---|
| 1596 | about creating a \c .sis file and installing it to device see also
|
---|
| 1597 | \l {The Symbian platform - Introduction to Qt#Installing your own applications}{here}.
|
---|
| 1598 |
|
---|
| 1599 | */
|
---|