Table of Contents
*.pro files
Description
For every Qt project there is a *.pro
file in the project directory that describes the project to qmake. The file takes its name from the project directory.
The project's {directory-name}.pro
file is typically created once in a project's lifetime and then edited to reflect configuration options, the addition of code files, etc.
Syntax
# | comment |
. | the current directory |
{PROPERTY} = {option} | sets an option |
{PROPERTY} += {option} | adds an option |
{PROPERTY} -+ {option} | removes an option |
File creation
To create a {directory-name}.pro
file in a project directory, run
qmake -project
in a terminal shell. If there are any source or other project files in the directory when the above is run, those files will be automatically included in {directory-name}.pro
.
Running qmake -project
when there is at least a main.cpp
(or similar) file will greatly simplify future modifications. Here is a virgin *.pro
file for a directory that has main.cpp
in it (where main.cpp is a Qt application):
###################################################################### # Automatically generated by qmake (2.01a) Tue Dec 7 17:15:59 2010 ###################################################################### TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . # Input SOURCES += main.cpp
In contrast, here is a virgin *.pro
file in a virgin (empty) directory:
###################################################################### # Automatically generated by qmake (2.01a) Tue Dec 7 17:07:32 2010 ###################################################################### TEMPLATE = subdirs # Directories
Enabling debug/release builds
In Unix (including Linux and OS X) you can explicitly specify debug and release build options:
CONFIG += debug_and_release
debug only:
CONFIG += debug
or release only:
CONFIG += release
These options will cause additional Makefiles to be made. If you do not specify an option in Unix, you will get a debug build (assuming the debug versions of Qt libraries are installed).
I have not yet tested Windows, but the above config option is supposedly not needed and/or invalid in Windows.
Adding source code files
To add the files {YourClass}.h
and {YourClass}.cpp
to your project, replace
SOURCES += main.cpp
with
SOURCES = main.cpp \ {YourClass}.cpp HEADERS = {YourClass}.h
Adding resource collection files
For a resource to be compiled into the binary the *.qrc file must be mentioned in the .pro file:
RESOURCES = foo.qrc
Additional Qt libraries
The QtCore and QtGUI libraries are included in all projects by default. To add additional Qt libraries to your project, include:
QT += {libname1} {libname2} ... {libnameN}
to remove:
QT -= {libname1}
where {libnameX}
is one of: network
, opengl
, sql
, xml
, support
. (Note: this list may not be complete as new libraries may have been added since this was written.)
The above names correspond to the QtNetwork, QtOpenGL, QtSQL, QtXML, and QtAssistantClient+Qt3Support libraries.