Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

[Prev: qmake Tutorial] [Home] [Next: qmake's Advanced Concepts]

qmake Concepts

Introducing qmake

qmake is an easy-to-use tool from Trolltech that creates makefiles for development projects across different platforms. qmake simplifies the generation of makefiles so that only a few lines of information are needed to create a makefile. qmake can be used for any software project whether it is written in Qt or not, although it also contains additional features to support Qt development.

qmake generates a makefile based on the information in a project file. Project files are created by the developer. Project files are usually simple, but can be quite sophisticated if required. qmake can also generate projects for Microsoft Visual studio without having to change the project file.

qmake's Concepts

The QMAKESPEC environment variable

Before qmake can be used to build makefiles, the QMAKESPEC environment variable must be set to the platform-compiler combination that is being used on the system. The QMAKESPEC environment variable tells qmake where to look to find platform and compiler specific information. This ensures that the right libraries are used, and that the generated makefile uses the correct syntax. A list of the currently supported platform-compiler combinations can be found in qt/mkspecs. Just set your environment variable to one of the directories listed.

For example, if you are using Microsoft Visual Studio on Windows, then you would set the QMAKESPEC environment variable to win32-msvc. If you are using gcc on Solaris then you would set your QMAKESPEC environment variable to solaris-g++.

Inside each of the directories in qt/mkspecs, there is a qmake.conf file which contains the platform and compiler specific information. These settings are applied to any project that is built using qmake and should not be modified unless you're an expert. For example, if all your applications had to link against a particular library, you might add this information to the relevant qmake.conf file.

Project (.pro) files

A project file is used to tell qmake the details it needs to know about creating a makefile for the application. For instance, a list of source files and header files that should be put into the project file; any application specific configuration, such as an extra library that should be linked against, or an extra include path.

'#' comments

You can add comments to project files. Comments begin with the '#' symbol and run to the end of the line.


The template variable tells qmake what sort of makefile should be generated for the application. The following choices are available:

The 'app' template

The 'app' template tells qmake to generate a makefile that will build an 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.

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

DESTDIR  = c:\helloapp
HEADERS += hello.h
SOURCES += hello.cpp 
SOURCES += main.cpp
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.

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.

The 'subdirs' template

The 'subdirs' template tells qmake to generate a makefile that will go into the specified subdirectories and generate a makefile for the project file in the directory and call make on it.

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 the sub directory 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 in that directory.

The CONFIG variable

The config variable specifies the options 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 recognised by qmake internally.

The following options control what compiler flags are used:

The following options define the type of library/application to be built:

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

    CONFIG += qt thread debug

Note, that you must use "+=", not "=", or qmake will not be able to use the settings used to build Qt as a guide as what type of Qt library was built.

[Prev: qmake Tutorial] [Home] [Next: qmake's Advanced Concepts]

Copyright © 2007 TrolltechTrademarks
Qt 3.3.8