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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

qmake Common Projects

This chapter describes how to set up qmake project files for three common project types that are based on Qt. Although all kinds of projects use many of the same variables, each of them use project-specific variables to customize output files.

Platform-specific variables are not described here; we refer the reader to the Deploying Qt Applications document for information on issues such as building universal binaries for Mac OS X and handling Visual Studio manifest files.

Building an Application

The app Template

The app template tells qmake to generate a Makefile that will build an application. With this template, the type of application can be specified by adding one of the following options to the CONFIG variable definition:

OptionDescription
windowsThe application is a Windows GUI application.
consoleapp template only: the application is a Windows console application.

When using this template the following qmake system variables are recognized. You should use these in your .pro file to specify information about your application.

  • HEADERS - A list of all the header files for the application.
  • SOURCES - A list of all the source files for the application.
  • FORMS - A list of all the UI files (created using Qt Designer) for the application.
  • LEXSOURCES - A list of all the lex source files for the application.
  • YACCSOURCES - A list of all the yacc source files for the application.
  • TARGET - Name of the executable for the application. This defaults to the name of the project file. (The extension, if any, is added automatically).
  • DESTDIR - The directory in which the target executable is placed.
  • DEFINES - A list of any additional pre-processor defines needed for the application.
  • INCLUDEPATH - A list of any additional include paths needed for the application.
  • DEPENDPATH - The dependency search path for the application.
  • VPATH - The search path to find supplied files.
  • DEF_FILE - Windows only: A .def file to be linked against for the application.
  • RC_FILE - Windows only: A resource file for the application.
  • RES_FILE - Windows only: A resource file to be linked against for the application.

You only need to use the system variables that you have values for, for instance, if you do not have any extra INCLUDEPATHs then you do not need to specify any, qmake will add in the default ones needed. For instance, an example project file might look like this:

 TEMPLATE = app
 DESTDIR  = c:/helloapp
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 DEFINES += QT_DLL
 CONFIG  += qt warn_on release

For items that are single valued, e.g. the template or the destination directory, we use "="; but for multi-valued items we use "+=" to add to the existing items of that type. Using "=" replaces the item's value with the new value, for example if we wrote DEFINES=QT_DLL, all other definitions would be deleted.

Building a Library

The lib Template

The lib template tells qmake to generate a Makefile that will build a library. When using this template, in addition to the system variables mentioned above for the app template the VERSION variable is supported. You should use these in your .pro file to specify information about the library.

When using the lib template, the following options can be added to the CONFIG variable to determine the type of library that is built:

OptionDescription
dllThe library is a shared library (dll).
staticlibThe library is a static library.
pluginThe library is a plugin; this also enables the dll option.

The following option can also be defined to provide additional information about the library.

  • VERSION - The version number of the target library, for example, 2.3.1.

The target file name for the library is platform-dependent. For example, on X11 and Mac OS X, the library name will be prefixed by lib; on Windows, no prefix is added to the file name.

Building a Plugin

Plugins are built using the lib template, as described in the previous section. This tells qmake to generate a Makefile for the project that will build a plugin in a suitable form for each platform, usually in the form of a library. As with ordinary libraries, the VERSION variable is used to specify information about the plugin.

  • VERSION - The version number of the target library, for example, 2.3.1.

Building a Qt Designer Plugin

Qt Designer plugins are built using a specific set of configuration settings that depend on the way Qt was configured for your system. For convenience, these settings can be enabled by adding designer to the project's CONFIG variable. For example:

 CONFIG      += designer plugin

See the Qt Designer Examples for more examples of plugin-based projects.

Building and Installing in Debug and Release Modes

Sometimes, it is necessary to build a project in both debug and release modes. Although the CONFIG variable can hold both debug and release options, the debug option overrides the release option.

Building in Both Modes

To enable a project to be built in both modes, you must add the debug_and_release option to your project's CONFIG definition:

 CONFIG += debug_and_release

 CONFIG(debug, debug|release) {
     TARGET = debug_binary
 } else {
     TARGET = release_binary
 }

The scope in the above snippet modifies the build target in each mode to ensure that the resulting targets have different names. Providing different names for targets ensures that one will not overwrite the other.

When qmake processes the project file, it will generate a Makefile rule to allow the project to be built in both modes. This can be invoked in the following way:

 make all

The build_all option can be added to the CONFIG variable in the project file to ensure that the project is built in both modes by default:

 CONFIG += build_all

This allows the Makefile to be processed using the default rule:

 make

Installing in Both Modes

The build_all option also ensures that both versions of the target will be installed when the installation rule is invoked:

 make install

It is possible to customize the names of the build targets depending on the target platform. For example, a library or plugin may be named using a different convention on Windows to the one used on Unix platforms:

 CONFIG(debug, debug|release) {
     mac: TARGET = $$join(TARGET,,,_debug)
     win32: TARGET = $$join(TARGET,,d)
 }

The default behavior in the above snippet is to modify the name used for the build target when building in debug mode. An else clause could be added to the scope to do the same for release mode; left as it is, the target name remains unmodified.

[Previous: qmake Tutorial] [Contents] [Next: Using qmake]

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Applications mobiles modernes avec Qt et QML

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.6
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