How to write the. Pro file in QT

Source: Internet
Author: User

 
In QT, a tool named qmake can generate a makefile, which is generated by the. Pro file. The. Pro file is written as follows:

1. Notes
Starting from "#" to the end of this line.

2. Specify the source file
Sources = *. cpp

Multiple source files can be separated by spaces, for example, sources = 1.cpp 2. cpp3.cpp
Or each file can be listed in a separate row, and a new row is initiated by a backslash, as shown in the following figure:

Sources = Hello. cpp
Main. cpp
A more lengthy method is to list each file separately, just like this:

Sources + = Hello. cpp
Sources + = Main. cpp

In this method, "+ =" is safer than "=" because it only adds new files to the existing list, rather than replacing the entire list.

3. Specify the header file
Headers = Hello. h or headers + = Hello. h

Any method used to list source files is also applicable to the first file.

4. configuration information
Config is used to tell qmake about the application configuration.

Config + = QT warn_on release

"+ =" Is used here because we add our configuration options to any existing one. It is safer to replace all specified options as "=.
A> the QT section tells qmake that the application uses QT to connect to the program. This means that qmake considers the QT library when connecting and adding the required include path for compilation.
B> the warn_on section tells qmake to set the compiler to output warning information.
C> the release section tells qmake that the application must be connected to a published application. In the development process, programmers can also use DEBUG to replace release.

5. Specify the target file name
Target = filename

If this project is not set, the target name is automatically set to the same name as the project file.

6. Add an interface file (UI)
Interfaces = filename. UI

7. Platform relevance Processing
What we need to do here is to use the corresponding scope for Processing Based on the platform that qmake runs. The simple scope of the platform-dependent files added for the Windows platform looks like this:

Win32 {
Sources + = hello_win.cpp
}

Therefore, if qmake runs on Windows, it adds hello_win.cpp to the source file list. If qmake runs on other platforms, 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 use the exists () function to check whether a file exists. We can use the error () function to stop running qmake. This works the same way as the scope. Simply use this function to replace the scope condition. Check the main. cpp file as follows:

! Exists (main. cpp ){
Error ("no main. cpp file found ")
}

"!" It is used to deny 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 more than one condition
Suppose you are using Windows and you want to see the qdebug () statement when running your application on the command line. You will not see the output unless you use console settings when you are connecting to your program. We can easily add the console to the config line, so that in windows, makefile will have this setting. But if we tell you that we just want to add the console when our application runs in windows and debug is already in the config line. This requires two nested scopes. You only need to generate one scope and then generate another one in it. Put the settings in the innermost scope, like this:

Win32 {
Debug {
Config + = console
}
}

Nested scopes can be connected by colons, as shown in the following code:

Win32: Debug {
Config + = console
}

10. touchpad
Template variables tell qmake which makefile is generated for this application. The following are available options:

A> app-create a makefile for the application. This is the default value, so if the template is not specified, this will be used.
B> Lib-create a makefile for the library.
C> vcapp-create a visual Studio project file for the application.
D> vclib-create a library's Visual Studio project file.
E> subdirs-this is a special template. It can create a makefile that can enter a specific directory, generate makefile for a project file, and call make for it.

11. Generate makefile
When you have created your project file, it is easy to generate the makefile. All you have to do is first go to the project file you generated and enter:

Makefile can be generated by the. Pro file as follows:

Qmake-omakefile hello. Pro

For Visual Studio users, qmake can also generate the ". DSP" file, for example:

Qmake-tvcapp-O hello. DSP hello. Pro



Welcome to the "blog migration" and "blog three caves" services provided by http://Blogmove.cn.

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.