|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

[Previous: qmake Tutorial] [Contents]

# qmake Common Projects

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

- Building an Application

- The `app` Template

- Building a Library

- The `lib` Template

## 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:

Option | Description
--- | ---
windows | The application is a Windows GUI application.
console | `app` 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 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:

        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 determine the type of library that is built:

Option | Description
--- | ---
dll | The library is a shared library (dll).
staticlib | The library is a static library.
plugin | The library is a plugin; this also enables the dll option.

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

[Previous: qmake Tutorial] [Contents]