A detailed introduction to the Pro file in QT

Source: Internet
Author: User
Tags win32

qt programs generally use the qmake tools provided by QT to compile.

The Qmake tool can use platform-independent. Pro files to generate platform-related makefile. The tool contains the necessary logic rules for invoking the QT built-in code generation tool (MOC,UIC,RCC).

You can enter qmake-project at the command line to generate platform-independent pro files.

Project file Pro is divided into three main categories: app (separate application), lib (Static and dynamic Library), Subdirs (recursive compilation). The project type can be specified by using the TEMPLATE variable. such as: TEMPLATE = App (default is not specified in the case of the app project)

For an app project or Lib project, there are these frequently used variables:

HEADERS: specifying C + + header files

SOURCES: specifying C + + implementation files

FORMS: Specifies UI files that need to be processed by UIC

RESOURCES: Specify QRC files that require RCC processing

defines: specifying pre-defined preprocessor symbols

Includepath: Specifies the C + + compiler search header file path

LIBS: Specify the library to link the project to

CONFIG: Specify project configuration and compilation parameters

qt: Specify the QT module to be used by the project

Version: Specify the target library revision number

TARGET: Specifies the base file name of the executable file or library, which defaults to the current directory name

DESTDIR: Specifies the directory where the executable file is placed

Dlldestdir: Specifies the directory where the target library file is placed

CONFIG: Specify project configuration and compilation parameters

The following is the main description of the config variable:

Debug: Compile executable file with debug information or library

Release: compilation does not have a debug information executable file or library (debug only works if debug release is specified at the same time)

Warn_off: Turn off a number of warnings, which are turned on by default

QT: Refers to applications using QT

DLL: Dynamic Compilation Library

Staticlib: Static Compilation Library

Plugin: Compiling a plugin

Console: The application needs to write the console

When we write the config variable, we can use the

For example: CONFIG = qt release Warn_off

or config = qt

CONFIG + = Release

CONFIG + = Warn_off

When you want to remove a setting: CONFIG-= Warn_off


In the pro file, you can enable VarName or {VarName} to access your own defined variables, such as


Myversion = 1.2

FILE = 1.cpp

TARGET = improve$${myversion}

SOURCES = $ $FILE

In the pro file, the usage of the Access environment variable is: $ (varName)

Pro file, access to QT configuration parameters usage: $$[varname]


When compiling on a different compilation platform, you need to set the conditions. Such as:
win32{
SOURCES + = 1.cpp
}else{

SOURCES + = 2.cpp}

Or

Win32:sources + = 3.cpp


In Qt, there is a tool qmake can generate a makefile file, it is generated by the. Pro file, the following is the wording of the. Pro file:

1. Notes
Start with "#" and end up in this line.

2. The template variable tells Qmake what kind of makefile to generate for this application. Here are the options to use:
TEMPLATE = App
A> App-Build an app for makefile. This is the default value, so if the template is not specified, this will be used.
B> Lib-Build a library of makefile.
C> Vcapp-Build an application's VisualStudio project file.
D> vclib-Create a library of VisualStudio project files.
E> Subdirs-This is a special template that creates a makefile that can go into a specific directory and generate makefile for a project file and call make for it.


#指定生成的应用程序放置的目录
DESTDIR + =. /bin

#指定生成的应用程序名
TARGET = Pksystem

#配置信息
Config is used to tell Qmake about application configuration information.

config+= QT warn_on Release

The use of "+ =" Here is because we add our configuration options to any one that already exists. This is more secure than replacing all the options that have been specified with "=".
The a> qt section tells Qmake that the app is connected using QT. This means that Qmake takes into account the QT library when connecting and adding the required include paths for compilation.
The b> warn_on section tells Qmake to set the compiler to output warning messages.
The C> release section tells the Qmake application to be connected to a published application. During the development process, the programmer can also use debug to replace the release


#指定uic命令将. ui files into the directory where the ui_*.h file is stored
Ui_dir + = Forms

#指定rcc命令将. qrc files to the storage directory for qrc_*.h files
Rcc_dir + =. /tmp

Storage directory for #指定moc命令将含Q_OBJECT的头文件转换成标准. h files
Moc_dir + =. /tmp

Storage directory for #指定目标文件 (obj)
Objects_dir + =. /tmp

#程序编译时依赖的相关路径
Dependpath + =. Forms include QRC sources

#头文件包含路径
Includepath + =. #qmake时产生的信息, "a reads the string of variable a", "(path) reads the environment variable PATH"

#message ($$ (PATH))

#源文件编码方式
CODECFORSRC = GBK

#工程中包含的头文件
HEADERS + = Include/painter.h
#工程中包含的. UI Design Files
FORMS + = Forms/painter.ui
#工程中包含的源文件
SOURCES + = Sources/main.cpp sources/painter.cpp
#工程中包含的资源文件
RESOURCES + = QRC/PAINTER.QRC

LIBS + = L FolderPath//The path of the introduced Lib file-L: Introduction Path

Release:libs + =-l FolderPath//release version introduced LIB file path

Debug:libs + =-L FolderPath//Debug version introduced LIB file path

Defines + = XX_XX_XXX//define compilation options that can be used in the. h file: #ifdefine xx_xx_xxx

Rc_file = Xxx.icns

7. Platform Dependency Processing
What we need to do here is to use the appropriate scopes for processing based on the platform that Qmake is running on. The simple scope of the platform-dependent files added for the Windows platform looks like this:

Win32 {
SOURCES + = Hello_win.cpp
}
======================================================================================================
When you've created your project file, it's easy to build makefile, all you have to do is go to the project file you generated and type it in:

Makefile can be generated like this by a ". Pro" File:

Qmake-o Makefile Hello.pro

For VisualStudio users, Qmake can also generate a ". DSP" file, for example:

Qmake-tvcapp-o HELLO.DSP Hello.pro


Reference Documentation:

A detailed introduction to the formulation of pro files in QT

Qt. Pro files in a detailed

QT Pro file written in detail, very useful, very important.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.