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. Specify the source file
SOURCES = *.cpp
For multi-source files, spaces can be separated, such as: SOURCES = 1.cpp 2.cpp3.cpp
or each file can be listed in a separate line, using a backslash to another line, like this:
SOURCES = Hello.cpp
Main.cpp
A more verbose approach is to list each file individually, just like this:
sources+= Hello.cpp
SOURCES +=main.cpp
Using "+ =" In this method is more secure than "=" because it simply adds a new file to an existing list instead of replacing the entire list.
3. Specify the header file
HEADERS = hello.h or HEADERS + = Hello.h
Any method that lists source files also applies to the header file.
4. Configuration information
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
5. Specify the target file name
TARGET = filename
If the item is not set, the target name is automatically set to the same name as the project file
6. Add interface files (UI)
INTERFACES = Filename.ui
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
}
So if Qmake is running on Windows, it will add hello_win.cpp to the list of source files. If Qmake is running on another platform, it will simply ignore this part.
8. If a file does not exist, stop qmake
If a file does not exist, you may not want to generate a makefile. We can check whether a file exists by using the exists () function. We can stop the running Qmake by using the error () function. This works the same way as scopes do. Simply replace the scope condition with this function. The check for the main.cpp file is like this:
!exists (main.cpp) {
Error ("No main.cpp file Found")
}
“!” To negate this test, for example, if the file exists, exists (main.cpp) is true, if the file does not exist,!exists (main.cpp) is true.
9. Check for more than one condition
Suppose you use Windows and you want to be able to see the qdebug () statement when you run your application at the command line. You won't see the output unless you're using the console setting when you're knitting your program. We can easily add the console to the Config line so that makefile will have this setting under Windows. But if we tell you we just want to add the console when our application is running under Windows and when debug is already in the Config line. This requires two nested scopes, as long as one scope is generated and then another is generated inside it. Put the settings in the innermost scope, just like this:
Win32 {
Debug {
CONFIG + = Console
}
}
Nested scopes can be concatenated with colons, like this:
Win32:debug {
CONFIG + = Console
}
10. Touch Plate
The template variable tells Qmake what kind of makefile to generate for this application. Here are the options to use:
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.
11. Generate Makefile
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-omakefile Hello.pro
For VisualStudio users, Qmake can also generate a ". DSP" file, for example:
Qmake-tvcapp-o HELLO.DSP Hello.pro
When we compile the QT project, we generally let qmake automatically generate it, but sometimes we need to customize our project, then we have to rewrite the pro file.
It's a little cumbersome to write all of your pro files, so it's usually run first.
Qmake-project
To generate a basic pro file.
For example, if you have a project directory for backup, the Backup.pro file will be generated in this directory.
For the general project, we only need to modify a few basic common options, the following say how to modify.
Let's say we have a directory named backup. Below are a.h,a.cpp,b.h,b.cpp,main.cpp and other files.
First we can run Qmake-project in the backup directory to generate the Backup.pro file.
888888888888888888888888888888888888888888888888888888888888888888
The first common way: #模块设置, generally set to app (build application, default), Subdirs (Generate makefile file compilation Subdirs specified subfolder), Lib (Build library file)
TEMPLATE = app# Specifies the directory where the generated application is placed
DESTDIR + =. /bin# specifying the generated application name
TARGET = pksystem# The configuration module for adding or reducing config, generally by default, but removing the Debug_and_release module does not generate the debug and release folders
#CONFIG + = Release
CONFIG-= debug_and_release# Specifies the UIC command to convert the. ui file into the directory where the ui_*.h file is stored
Ui_dir + = forms# Specify the RCC command to convert the. qrc file to the storage directory for the qrc_*.h file
Rcc_dir + =. /tmp# specifies that the MOC command converts the header file containing the Q_object to the storage directory of the standard. h file
Moc_dir + =. /tmp# Specify the directory where the target files are stored
Objects_dir + =. /tmp# Dependent path for program compilation
Dependpath + =. Forms include QRC sources# header file contains path
Includepath + = #qmake时产生的信息, $${a} reads the string of variable A, $$ (path) reads the environment variable PATH
#message ($$ (PATH)) #源文件编码方式
CODECFORSRC = gbk# Input
#工程中包含的头文件
HEADERS + = include/painter.h# Project included in the. UI design File
FORMS + = forms/painter.ui# source files included in the project
SOURCES + = Sources/main.cpp sources/painter.cpp# resource files included in the project
RESOURCES + = QRC/PAINTER.QRC The second commonly used method for sub-folder compilation: #设定模块为子文件夹编译方式
TEMPLATE = Subdirs
#子文件夹目录, available \ line break
Subdirs = src1 \
Src2
Several basic options have been included in the Backup.pro, such as
Template,target,includepath,heads,sources and other options.
Here are a few frequently modified options.
HEADS:
The header files in our project are as follows:
HEADS + = a.h \
B.h
SOURCES:
The CPP file in our project is as follows:
SOURCES + = a.cpp \
B.cpp \
Main.cpp
The above two options of the file branch is a backslash \ to branch, the last one, if the same line of files can be separated by space, we in the execution of Qmake-project, Qmake has automatically helped us write, save us these troubles, but later to increase the file can be added here.
Includepath:
This option allows us to specify the directory in which we include the header file, if you have other headers that are not in the current directory, and you do not want to include the header file in your own source file with an absolute or relative path, then I can include the path where the header file is located. For example, in the backup directory of the sibling directory has a directory of image directory, there is a header file for image.h, our b.h to use, so we set in Backup.pro file Includepath to
Includepath + =. /image
In this way, we only need to include "image.h" in the b.h.
CONFIG:
One of the most common uses of config is to set the release version or the version information for debug or Release and Debug. This can be set if we want to debug.
CONFIG + = Debug
or config + = release (release version)
Here are the options for several versions of Config:
Release the project is to being built in release mode. This was ignored if debug is also specified.
Debug the project is to being built in debug mode.
Debug_and_release the project is built in both debug and release modes. This can has some unexpected side effects (see below for more information).
Build_all If Debug_and_release is specified, the project was built in both debug and release modes by default.
Ordered when using the Subdirs template, this option specifies the directories listed should is processed in the OR Der in which they is given.
Precompile_header enables support for the use of precompiled headers in projects.
warn_on the compiler should output as many warnings as possible. This is ignored if Warn_off is specified.
Warn_off the compiler should output as few warnings as possible.
LIBS:
Here we can choose the library we want to include, for example, our project will use a compression library of libz.so, how can I write:
LIBS + =-lz
Or use the Libimage.so library in our image directory, then you can write:
LIBS + =-L. /image/image
Defines:
Defines is a common set of us, which is the equivalent of our-D definition with GCC. For example, our backup project needs to read and write large files so that we can define them:
Defines + = _largefile64_source _file_offset_bits=64
RESOURCES:
Define our resource profile, we need a lot of pictures in the project, then the definition of these images can be described in the BACKUP.QRC file, then we can point out our QRC file.
RESOURCES + = BACKUP.QRC
TARGET:
This option allows us to define the name of the target file we generated, for example, we execute our backup project which is the default generation of the backup execution file, but we want our executable file named Abcbackup, we can write
TARGET = Abcbackup
Objects_dir:
In general we generate a lot of intermediate files when compiling our project, such as. o Files (under Linux) or. obj (under Windows), so our project is messy, so we can define this option, and we can define this:
Objects_dir + =/objs
So, all of our intermediate files are in the BACKUP/OBJS directory.
Generally, we will not compile directly in our project, so that the project is messy, we can create a directory in the backup directory, for the Bakcup-build directory, we compile in this directory, so that the other temporary files in this directory, So our project doesn't look so messy.
We go into the Bakcup-build directory and run
Qmake-o Makefile. /bakcup.pro
This allows us to generate a makefile in the current directory. Execute make in this directory to generate our Abcbackup executable.
Transferred from: http://blog.csdn.net/metasearch/article/details/2148207
How to do the. Pro file in QT