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

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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