Preparation of the Pro file in QT

Source: Internet
Author: User

 

When compiling the QT project, we usually make qmake automatically generated. But sometimes we need to customize our project, so we must rewrite the pro file.

It is a little troublesome to write all the pro files on your own. Therefore, it is generally run first.

Qmake-Project

To generate the basic pro file.

 

For example, if you have a project directory named backup, the backup. Pro file will be generated under this directory.

 

For general projects, we only need to modify a few basic common options. The following describes how to modify them.

 

Suppose we have a directory named backup. The following are a. h, A. cpp, B. H, B. cpp, Main. cpp, and other files.

First, run qmake-project in the backup directory to generate the backup. Pro file.

 

888888888888888888888888888888888888888888888888888888888888888888

The first common method: # module setting, which is generally set to app (generating application, default), subdirs (generating MAKEFILE file to compile the sub-Folder specified by subdirs), lib (generating library files)
Template = app # specify the directory where the generated application is stored
Destdir + = ../bin # specify the name of the generated Application
Target = pksystem # add or remove the config configuration module. The default setting is generally used, but the debug and release folders are not generated except the debug_and_release module.
# Config + = release
Config-= debug_and_release # specify the UIC command to convert the. UI file to the directory where the UI _ *. h file is stored.
Ui_dir + = forms # specify the RCC command to convert the. qrc file to the directory where the qrc _ *. h file is stored.
Rcc_dir + = ../tmp # specify the MOC command to convert the header file containing q_object to the directory where standard. H files are stored.
Moc_dir + = ../tmp # specify the directory where the target file is stored
Objects_dir + = ../tmp # related paths on which the program depends during compilation
Dependpath + =. forms include qrc sources # header file inclusion path
Includepath + =. # information generated during qmake, $ {A} reads the string of variable A, $ (PATH) reads the environment variable path
# Message ($ (PATH) # source file encoding method
Codecforsrc = GBK # Input
# Header files contained in the project
Headers + = include/painter. h #. uidesign file included in the project
Forms + = forms/painter. UI # source files contained in the project
Sources + = sources/Main. cpp sources/painter. cpp # resource files contained in the project
Resources + = qrc/painter. qrc second common method for compiling subfolders: # Set the module to the subfolders Compilation Method
Template = subdirs

# Subfolder directory, available \ line feed
Subdirs = src1 \
Src2

Several Basic options are included in backup. Pro, such

Template, target, includepath, heads, sources, and other options.

 

The following describes several 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 preceding two options use the backslash \ to separate the file branches. The last one does not need to be used. Files in the same row can be separated by spaces. When we execute qmake-project, qmake has automatically helped us write it out, saving us the trouble, but you can add files here to add them later.

 

Includepath:

This option can specify the # include statement to include the directory of the header file. If you have other header files that are not included in the current directory, I don't want to use absolute or relative paths to include header files in my source files, so I can include the path of this header file here, for example, in the backup directory's sibling directory, there is a directory named image, which contains a header file named image. h, our B. h. set includepath

Includepath + = ../Image

In this way, we only need to # include "image. H" in B. H.

 

Config:

One common use of config is to set the release version or the version information of debug, release, and debug. If you want to debug it, you can set it like this.

Config + = debug

Or config + = release (Release Version)

Below are the options for several versions of config:

Release the project is to be built in release mode. This is ignored If debug is also specified.

Debug the project is to be built in debug mode.
Debug_and_release the project is built in both Debug and release modes. This can have some unexpected side effects (see below for more information ).

Build_all if debug_and_release is specified, the project is built in both Debug and release modes by default.

Ordered when using the subdirs template, this option specifies that the directories listed shoshould be processed in the order in which they are given.

Precompile_header enables support for the use of precompiled headers in projects.

Warn_on the compiler shocould output as warnings as possible. This is ignored if warn_off is specified.

Warn_off the compiler shocould output as few warnings as possible.

Libs:

Here we can select the library we want to include. For example, we need to use a compression library of libz. So in our project. How can I write it:

Libs + =-LZ

Or use the libimage. So library in our image directory, you can write it like this:

Libs + =-l ../image/Image

 

Defines:

Defines is a common requirement. It is equivalent to the-D definition of GCC. For example, our backup project needs to read and write large files, which can be defined as follows:

Defines + = _ largefile64_source _ file_offset_bits = 64

 

Resources:

Define our Resource Description file. We need a lot of images in our project, so the definition of these images can be described in the backup. qrc file, so here 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, when we execute this backup project, the backup execution file is generated by default, but if we want to name our execution as abcbackup, we can write it like this.

Target = abcbackup

 

 

Objects_dir:

We usually generate many intermediate files when compiling our project, such. O files (in Linux) or. OBJ (in Windows), so our project is messy, so we can define this option. We can define it as follows:

Objects_dir + =./objs

In this way, all of our intermediate files are under the backup/objs directory.

 

In general, we will not compile it directly in our project. In this case, the project is messy. We can create a directory under the Backup Directory, which is the bakcup-build directory, we compile in this directory so that other temporary files are in this directory, so that our project will not look so messy.

Go to the bakcup-build directory and run

Qmake-O makefile ../bakcup. Pro

In this way, a makefile is generated under the current directory. Execute make in this directory to generate our abcbackup executable program.

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.