Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Deploying an Application on Qt/Windows

This documentation will describe how to determine which files you should include in your distribution, and how to make sure that the application will find them at run-time. We will demonstrate the procedures in terms of deploying the Plug & Paint application that is provided in Qt's examples directory.

Contents:

Static Linking

If you want to keep things simple by only having a few files to deploy, i.e. a stand-alone executable with the associated compiler specific DLLs, then you must build everything statically.

Building Qt Statically

Before we can build our application we must make sure that Qt is built statically. To do this, go to a command prompt and type the following:

 cd C:\path\to\Qt
 configure -static <any other options you need>

Remember to specify any other options you need, such as data base drivers, as arguments to configure. Once configure has finished, type the following:

 nmake sub-src

This will build Qt statically. Note that we have used nmake in all the examples, but if you use MinGW you must use the mingw32-make instead.

Linking the Application to the Static Version of Qt

Once Qt has finished building we can build the Plug & Paint application. First we must go into the directory that contains the application:

 cd examples\tools\plugandpaint

We must then run qmake to create a new makefile for the application, and do a clean build to create the statically linked executable:

 nmake clean
 qmake -config release
 nmake

You probably want to link against the release libraries, and you can specify this when invoking qmake. Now, provided that everything compiled and linked without any errors, we should have a plugandpaint.exe file that is ready for deployment. One easy way to check that the application really can be run stand-alone is to copy it to a machine that doesn't have Qt or any Qt applications installed, and run it on that machine.

Remember that if your application depends on compiler specific libraries, these must still be redistributed along with your application. You can check which libraries your application is linking against by using the depends tool. For more information, see the Application Dependencies section.

The Plug & Paint example consists of several components: The application itself (Plug & Paint), and the Basic Tools and Extra Filters plugins. Since we cannot deploy plugins using the static linking approach, the application we have prepared is incomplete. It will run, but the functionality will be disabled due to the missing plugins. To deploy plugin-based applications we should use the shared library approach.

Shared Libraries

We have two challenges when deploying the Plug & Paint application using the shared libraries approach: The Qt runtime has to be correctly redistributed along with the application executable, and the plugins have to be installed in the correct location on the target system so that the application can find them.

Building Qt as a Shared Library

We assume that you already have installed Qt as a shared library, which is the default when installing Qt, in the C:\path\to\Qt directory. For more information on how to build Qt, see the Installation documentation.

Linking the Application to Qt as a Shared Library

After ensuring that Qt is built as a shared library, we can build the Plug & Paint application. First, we must go into the directory that contains the application:

 cd examples\tools\plugandpaint

Now run qmake to create a new makefile for the application, and do a clean build to create the dynamically linked executable:

 nmake clean
 qmake -config release
 nmake

This builds the core application, the following will build the plugins:

 cd ..\plugandpaintplugins
 nmake clean
 qmake -config release
 nmake

If everything compiled and linked without any errors, we will get a plugandpaint.exe executable and the pnp_basictools.dll and pnp_extrafilters.dll plugin files.

Creating the Application Package

To deploy the application, we must make sure that we copy the relevant Qt DLL (corresponding to the Qt modules used in the application) as well as the executable to the same directory in the release subdirectory.

Remember that if your application depends on compiler specific libraries, these must be redistributed along with your application. You can check which libraries your application is linking against by using the depends tool. For more information, see the Application Dependencies section.

We'll cover the plugins shortly, but first we'll check that the application will work in a deployed environment: Either copy the executable and the Qt DLLs to a machine that doesn't have Qt or any Qt applications installed, or if you want to test on the build machine, ensure that the machine doesn't have Qt in its environment.

If the application starts without any problems, then we have successfully made a dynamically linked version of the Plug & Paint application. But the application's functionality will still be missing since we have not yet deployed the associated plugins.

Plugins work differently to normal DLLs, so we can't just copy them into the same directory as our application's executable as we did with the Qt DLLs. When looking for plugins, the application searches in a plugins subdirectory inside the directory of the application executable.

So to make the plugins available to our application, we have to create the plugins subdirectory and copy over the relevant DLLs:

 plugins\pnp_basictools.dll
 plugins\pnp_extrafilters.dll

An archive distributing all the Qt DLLs and application specific plugins required to run the Plug & Paint application, would have to include the following files:

ComponentFile Name
The executableplugandpaint.exe
The Basic Tools pluginplugins\pnp_basictools.dll
The ExtraFilters pluginplugins\pnp_extrafilters.dll
The Qt Core moduleqtcore4.dll
The Qt GUI moduleqtgui4.dll

In addition, the archive must contain the following compiler specific libraries depending on your version of Visual Studio:

VC++ 6.0VC++ 7.1 (2003)VC++ 8.0 (2005)
The C run-timemsvcrt.dllmsvcr71.dllmsvcr80.dll
The C++ run-timemsvcp60.dllmsvcp71.dllmsvcp80.dll

To verify that the application now can be successfully deployed, you can extract this archive on a machine without Qt and without any compiler installed, and try to run it.

An alternative to putting the plugins in the plugins subdirectory is to add a custom search path when you start your application using QApplication::addLibraryPath() or QApplication::setLibraryPaths().

 qApp->addLibraryPath("C:\some\other\path");

One benefit of using plugins is that they can easily be made available to a whole family of applications.

It's often most convenient to add the path in the application's main() function, right after the QApplication object is created. Once the path is added, the application will search it for plugins, in addition to looking in the plugins subdirectory in the application's own directory. Any number of additional paths can be added.

Visual Studio 2005

When deploying an application compiled with Visual Studio 2005 there are some additional considerations that need to be handled.

First, we need to copy the manifest file created when linking the application. This manifest file contains information about the application's dependencies on side-by-side assemblies, such as the runtime libraries. The manifest file needs to be copied into the same folder as the application executable. You do not need to copy the manifest files for shared libraries (DLLs), since they are not used. If the shared library has different dependencies than the application using it, the manifest file needs to be embedded into the DLL binary. In Qt 4.1.3 and later we have the following CONFIG options for embedding manifests:

 embed_manifest_dll
 embed_manifest_exe

To use the options, add

 CONFIG += embed_manifest_exe

to your .pro file. The embed_manifest_dll option is enabled by default.

You can find more information about manifest files and side-by-side assemblies at the MSDN website.

We also need to include the runtime libraries. To do this, copy the contents of

 <Visual Studio Install Path>\VC\redist\<Architecture>\Microsoft.VC80.CRT

into the folder where your executable is.

Application Dependencies

Additional Libraries

Depending on configuration, compiler specific libraries must be redistributed along with your application. You can check which libraries your application is linking against by using the Dependency Walker tool. All you need to do is to run it like this:

 depends <application executable>

This will provide a list of the libraries that your application depends on and other information.

When looking at the release build of the Plug & Paint executable (plugandpaint.exe) with the depends tool, the tool lists the following immediate dependencies to non-system libraries:

QtVC++ 6.0VC++ 7.1 (2003)VC++ 8.0 (2005)MinGW
  • QTCORE4.DLL - The QtCore runtime
  • QTGUI4.DLL - The QtGui runtime
  • MSVCRT.DLL - The C runtime
  • MSVCP60.DLL - The C++ runtime (only when STL is installed)
  • MSVCR71.DLL - The C runtime
  • MSVCP71.DLL - The C++ runtime (only when STL is installed)
  • MSVCR80.DLL - The C runtime
  • MSVCP80.DLL - The C++ runtime (only when STL is installed)
  • MINGWM10.DLL - The MinGW run-time

When looking at the plugin DLLs the exact same dependencies are listed.

Qt Plugins

Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application.

The search path for Qt plugins (as well as a few other paths) is hard-coded into the QtCore library. By default, the first plugin search path will be hard-coded as C:\path\to\Qt\plugins. Using pre-determined paths has certain disadvantages. For example, they may not exist on the target machine. For that reason you need to examine various alternatives to make sure that the Qt plugins are found:

[Deploying Qt Applications]

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 23
  2. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 46
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  6. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 50
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 23
  5. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 46
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Developer Network au hasard

Logo

Installation de PySide : binaires et compilation

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web