source: trunk/doc/src/deployment.qdoc@ 342

Last change on this file since 342 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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