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  · 

qmake Project Files

Project files contain all the information required by qmake to build your application, library, or plugin. The resources used by your project are generally specified using a series of declarations, but support for simple programming constructs allow you to describe different build processes for different platforms and environments.

Project File Elements

The project file format used by qmake can be used to support both simple and fairly complex build systems. Simple project files will use a straightforward declarative style, defining standard variables to indicate the source and header files that are used in the project. Complex projects may use the control flow structures to fine-tune the build process.

The following sections describe the different types of elements used in project files.

Variables

In a project file, variables are used to hold lists of strings. In the simplest projects, these variables inform qmake about the configuration options to use, or supply filenames and paths to use in the build process.

qmake looks for certain variables in each project file, and it uses the contents of these to determine what it should write to a Makefile. For example, the list of values in the HEADERS and SOURCES variables are used to tell qmake about header and source files in the same directory as the project file.

Variables can also be used internally to store temporary lists of values, and existing lists of values can be overwritten or extended with new values.

The following lines show how lists of values are assigned to variables:

    HEADERS = mainwindow.h paintwidget.h

Note that the first assignment only includes values that are specified on the same line as the SOURCES variable. The second assignment splits the items across lines by using the \ character.

The list of values in a variable is extended in the following way:

    SOURCES = main.cpp mainwindow.cpp \
              paintwidget.h
    CONFIG += qt

The CONFIG variable is another special variable that qmake uses when generating a Makefile. It is discussed in the section on configuration later in this chapter. In the above line, QT is added to the list of existing values contained in CONFIG.

The following table lists the variables that qmake recognizes, and describes what they should contain.

VariableContents
CONFIGGeneral project configuration options.
DESTDIRThe directory in which the executable or binary file will be placed.
FORMSA list of .ui files to be processed by uic.
HEADERSA list of filenames of header (.h) files used when building the project.
QTQt-specific configuration options.
RESOURCESA list of resource (.rc) files to be included in the final project. See the The Qt Resource System for more information about these files.
SOURCESA list of source code files to be used when building the project.
TEMPLATEThe template to use for the project. This determines whether the output of the build process will be an application, a library, or a plugin.

The contents of a variable can be read by prepending the variable name with $$. This can be used to assign the contents of one variable to another:

    TEMP_SOURCES = $$SOURCES

The $$ operator is used extensively with built-in functions that operate on strings and lists of values. These are described in the chapter on qmake Advanced Usage.

Normally, variables are used to contain whitespace-separated lists of values. However, it is sometimes necessary to specify values containing spaces. These must be quoted in the following way:

    DEST = "Program Files"

The quoted text is treated as a single item in the list of values held by the variable.

Comments

You can add comments to project files. Comments begin with the # symbol and continue to the end of the same line. For example:

    # Comments usually start at the beginning of a line, but they
    # can also follow other content on the same line.

Built-in Functions and Control Flow

qmake provides a number of built-in functions to allow the contents of variables to be processed. The most commonly used function in simple project files is the include function which takes a filename as an argument. The contents of the given file are included in the project file at the place where the include function is used. The include function is most commonly used to include other project files:

    include(other.pro)

Support for conditional structures is made available via scopes that behave like if statements in programming languages:

    win32 {
        SOURCES += paintwidget_win.cpp
    }

The assignments inside the scope are only made if the condition is true. In this case, the special win32 variable must be set; this happens automatically on Windows, but this can also be specified on other platforms by running qmake with the -win32 command line option (see Running qmake for more information).

Simple loops are constructed by iterating over lists of values using the built-in for function. The following code adds directories to the SUBDIRS variable, but only if they exist:

    EXTRAS = handlers tests docs
    for(dir, EXTRAS) {
        exists($$dir) {
            SUBDIRS += $$dir
        }
    }

More complex operations on variables that would usually require loops are provided by built-in functions such as find, unique, and count. These functions, and many others are provided to manipulate strings and paths, support user input, and call external tools. A list of the functions available can be found in the qmake Advanced Usage chapter of this manual.

Project Templates

The TEMPLATE variable is used to define the type of project that will be built. If this is not declared in the project file, qmake assumes that an application should be built, and will generate an appropriate Makefile (or equivalent file) for the purpose.

The types of project available are listed in the following table with information about the files that qmake will generate for each of them:

TemplateDescription of qmake output
app (default)Creates a Makefile to build an application.
libCreates a Makefile to build a library.
subdirsCreates a Makefile that will go into the specified directories and run qmake on any project files found.
vcappCreates a Visual Studio Project file to build an application.
vclibCreates a Visual Studio Project file to build a library.

See the qmake Tutorial for advice on writing project files for projects that use the app and lib templates.

When the subdirs template is used, qmake generates a Makefile to examine each specified subdirectory, process any project file it finds there, and run the platform's make tool on the newly-created Makefile.

The only system variable that is recognised for this template is the SUBDIRS variable. This variable contains a list of all the subdirectories that contain project files to be processed. It is essential that the project file in each subdirectory has the same name as the subdirectory, so that qmake can find it. For example, if the subdirectory is called myapp then the project file in that directory should be called myapp.pro.

General Configuration

The CONFIG variable specifies the options and features that the compiler should use and the libraries that should be linked against. Anything can be added to the CONFIG variable, but the options covered below are recognized by qmake internally.

The following options control the compiler flags that are used to build the project:

OptionDescription
releaseThe project is to be built in release mode. This is ignored if debug is also specified.
debugThe project is to be built in debug mode.
warn_onThe compiler should output as many warnings as possible. This is ignored if warn_off is specified.
warn_offThe compiler should output as few warnings as possible.

Note that each of the options specified in the CONFIG variable can also be used as a condition in scopes. This enables different configurations to be defined for release and debug builds, and is described in more detail in the Scopes section of the Advanced Usage chapter of this manual.

The following options define the type of project to be built. Note that some of these options only take effect when used on the relevant platform. On other platforms, they have no effect.

OptionDescription
qtThe project is a Qt application and should link against the Qt library. You can use the QT variable to control any additional Qt modules that are required by your application.
threadThe project is a multi-threaded application.
x11The project is an X11 application or library.

When using the app or lib templates, more specialized configuration options can be used to fine tune the build process. These are explained in details in the Common Projects chapter of this manual.

For example, if your application uses the Qt library and you want to build it as a multi-threaded application in debug mode, your project file will contain the following line:

    CONFIG += qt thread debug

Note, that you must use "+=", not "=", or qmake will not be able to use Qt's configuration to determine the settings needed for your project.

Declaring Qt Libraries

If you enable qmake's support for Qt with the CONFIG variable, it is possible to further specify which of the Qt libraries you will link with your application. This is achieved with the QT variable which can be used to declare the required extension modules. For example, we can enable the XML and network modules in the following way:

    CONFIG += qt
    QT += network xml

Note that QT includes the core and GUI modules by default, so the above declaration adds the network and XML modules to this default list. The following assignment omits the default modules, and will lead to errors when the application's source code is being compiled:

    QT = network xml # This will omit the core and GUI modules.

If you want to build a project without the GUI module, you need to exclude it with the "-=" operator. By default, QT contains both core and gui, so the following line will result in a minimal Qt project being built:

    QT -= gui # Only the core module is used.

The table below shows the options that can be used with the QT variable and the features that are associated with each of them:

OptionFeatures
core (included by default)QtCore module
gui (included by default)QtGui module
networkQtNetwork module
openglQtOpenGL module
sqlQtSql module
xmlQtXml module
qt3supportQt3Support module

Configuration Features

qmake can be set up with extra configuration features that are specified in feature (.prf) files. These extra features often provide support for custom tools that are used during the build process. To add a feature to the build process, append the feature name (the stem of the feature filename) to the CONFIG variable.

For example, qmake can configure the build process to take advantage of external libraries that are supported by pkg-config, such as the D-BUS and ogg libraries, with the following lines:

        CONFIG += link_pkgconfig
        PKGCONFIG += ogg dbus-1

More information about features can be found in the Adding New Configuration Features section of the qmake Advanced Usage chapter.

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 82
  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. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. 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
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Developer Network au hasard

Logo

La création de colonnes dans une ListView en 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.0
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