Qmake understand (you can also join Lex yacc files)

Source: Internet
Author: User
Tags qt designer

About Qmake, a good time to make me confused, do not know what to do, only know how to use, but also only understand so one or two orders, detailed reading of the information after finishing as follows:

1. First, perceptual understanding is that Qmake can use source files (including header file h, implement file Cpp,qt UI files, etc.) to generate a variety of different types of works, engineering needs makefile files, executable and unenforceable, depending on the template used (including app, Lib, Subdirs, Vcapp, Vclib).

2. Create pro file, add various source files, also can set different platform related source files, set up various rules, use qmake command to generate project. Later, the pro file can be written manually, or you can take advantage of the qmake command intelligence generation.

The general order is to create the. Pro file first, and then generate the makefile file by the. Pro file, the makefile file holds the compiler and connector parameter options, and also describes the relationship between all source files (the specific include files required by the source code file, the executable file that contains the target file module Blocks and libraries, etc.). The Creator (make program) reads the makefile file first, then activates the compiler, assembler, resource compiler, and connector to produce the final output, and the final output is usually an executable file. The creator uses built-in inference rules to activate the compiler, To produce a specific obj file by compiling the specific CPP file.

3. The various templates generate different types of projects, and each template can be used with qmake variables that are not the same:

App Template: Compiling an executable program

Option description

Windows program is the interface Program of window platform

Console App template dedicated: Program is window Platform Console program

When you use this template, some of the following qmake variables are available, and you can use these variables in the pro file to configure the relevant information that your application needs

A list of header files that need to be compiled in the headers– program.

SOURCES-the list of source files that need to be compiled in the program.

forms– the list of UI files created by QT Designer for the program (Qte2 is interfaces).

A list of all the lex source files used by the lexsources– program.

Yaccsources-a list of all the YACC source files used by the program.

target– the name of the executable. The default is the same as the project file name (which is automatically added depending on the platform suffix name).

destdir– the published directory of the executable file.

The defines– program compiles a list of directories required by the predefined list of includepath– programs needed for the header file.

dependpath– a dependent path for the program search.

vpath– find the search path to the supplied file (I haven't figured out ~_~ yet).

Def_file–windows platform Dedicated: The program needs to use the. def.

Rc_file–windows platform Dedicated: The program's resource files.

Res_file–windows platform Dedicated: The program needs to connect the resource files.

Lib Template library:

Lib template tells Qmake generated makefile is going to compile a library, when using this template, additional system variables will be added to the above app template mentioned variables, because the app template is support version variable, you should use these in pro file to develop some library information
When using this template, the following options can be added to the CONFIG variable to determine which library to compile into
Option description

DLL is compiled into a dynamic library (DLL or so).

Staticlib compiled into a static library.

Plugin compiled into a plug-in library, this option means that the DLL is also set.

version– The version number of the target library, such as 2.3.1

Compile into a plugin
The plugin is compiled using the Lib template, which, as described above, tells Qmake that the generated makefile is the plug-in that will be compiled into the appropriate form for each platform. Usually in the form of a library, the version variable is used to specify some information about the plug-in.
version– The version number of the target library, such as 2.3.1

Declaring the QT library module

If the config variable contains the QT value, it indicates that Qmake supports QT programs, but it also needs to adjust some of the QT modules that are used in your program. This is achieved by using the QT variable. QT is used to declare some of the additional modules used. For example, by using the following method, we make the XML and the Network module effective

CONFIG + = qt

QT + = Network xml

Note that QT includes the core and GUI modules by default, so the above declaration adds XML and network modules to the default list. The following statement ignores the default module and causes an error when compiling the program source code.

QT = Network XML # This would omit the core and GUI modules.

If you want to compile a project that does not require a GUI module, you need to use the "-=" operation symbol to remove the inclusion, by default Qt contains both the core and GUI two modules, so the following statement is a small QT project will be compiled

QT-= GUI # Only the core module is used.

The table below shows the options that the QT variable can use and explains the corresponding features

Core (included by default) Qtcore module

GUI (included by default) Qtgui module interface modules

Network Qtnetwork module supports networking modules

OpenGL QTOPENGL Module supports OpenGL image programming

SQL Qtsql module supports SQL database driver

SVG qtsvg module supports SVG vector graphics

XML qtxml module supports XML modules

Qt3support Qt3support Module supports QT3 class

Note that adding OpenGL to the QT variable is equivalent to adding it to the config variable, so there is no need to add OpenGL options to the QT variable and config variable at the same time for the QT application

Declaring the QT library module

Qmake can set additional configuration features by using a dedicated PRF file. These features are typically provided for use by custom tools at compile time. To add an attribute to the process, add an attribute name to the config variable with the same name as the file name of the attribute (mkspecs\ Features directory)

For example, Qmake can use Pkg-config to provide additional libraries for support during the compilation process, such as the D-bus Library and the Ogg library, using the following method

CONFIG + = Link_pkgconfig

Pkgconfig + = Ogg dbus-1
declaring other libraries

If you need to use the other libraries in the project, you need to specify in the project file, let Qmake find the path of the library and the corresponding library to be connected, you can add in the Libs variable. The path to the library to give, or the common Unix-style notation to specify the library and library path, For example, the following shows how to use the specified library

LIBS + =-l/usr/local/lib-lmath

You can use a similar method to specify the path to the header file, but use the Includepath variable, such as the path where several header files may be added below

Includepath = C:/msdev/include D:/stl/include

But my habit is the following, more clear also, the best path of Windows do not have spaces, Chinese also do not have, Slash is also recommended/instead of Windows \ Because with the branch symbol \ is the same/can be used in UNIX and Windows, but \ It seems that UNIX or Linux is not going to work, so use/IS universal

Includepath = c:/msdev/include \

D:/stl/include

Options

In the command line, specifying some options for Qmake is for customizing the compilation process. and covers the platform for the default settings for Qmake, the following basic options provide usage information, specify Qmake write to the output file there, control the level of debug information in the console print out.

Help List Qmake Help information

The O. file is output directly to the files. If this option is not specified, Qmake will attempt to use the appropriate file name as the output, depending on the current operating mode. If '-' is specified, the output will be printed directly on the console.

d lists debug information for Qmake because the project needs to be compiled on each target platform, and there are many subdirectories, you can use the following options when running Qmake to set the corresponding variable for the specified platform.

Unix qmake runs in UNIX mode. In this mode, UNIX-style file naming rules and path transformations will be used, and another test UNIX domain is successful. This is the default mode for UNIX platforms.

Macx Qmake runs in Mac OS x mode. In this mode, UNIX-style file naming rules and path transformations will be used, and the other test MACX domain is successful. This is the default mode for Mac OS x platform.

Win32 Qmake runs in Win32 mode. In this mode, the Windows-style file naming conventions and path transformations will be used, and the other test Win32 domain is successful. This is the default mode for Windows platforms. Project templates are typically specified within the template variable of the pro file. We can use the following options to override or overwrite:

• t Tmpl Qmake will use Tmpl to rewrite any settings of the template variable, but only after the pro file is processed.

TP prefix qmake will add prefix to the template variable. Adjusting the level of warning messages can help you find the problem with your Pro file:

· Wall Qmake will report all known warning messages.

· Wnone Qmake does not produce any warning messages.

· Wparserqmake only produces a warning of lexical analysis. When parsing your pro file, you will be alerted to some common pitfalls and potential problems.

· Wlogic Qmake warns you that there are some common in pro files

Makefile mode options

qmake-makefile [Options] Files

In Makefile mode, Qmake will generate Makefile files for compiling the project, and the following options may be used in this mode to affect how the project files are generated:

after Qmake will handle some command-line tasks after the specified file

NoCache Qmake will be ignored. Qmake.cache file.

Nodepend Qmake will not produce any dependent information.

cache file Qmake will use the specified buffered file and ignore the other found. qmake.cache files.

Spec Spec Qmake will use spec as the path and compiler information for the platform, and the value set by the environment variable QMAKESPEC will be ignored.

You can also pass the Qmake parameters at the command line; they will be processed before all the specified files:

Qmake-makefile-unix-o makefile "Config+=test" Test.pro

The above means that in UNIX mode, using the Test.pro join Test option to generate makefile, but some of the specified options when they are default is not necessary to add, so if on UNIX is the following

Qmake "Config+=test" Test.pro

You can pass the-after option if you are sure you want to process some variables behind the specified file. When this is specified, the command line all tasks are delayed after the –after option until the specified file is passed in.

Project mode options

Project Mode Options

qmake-project [Options] Files

In engineering mode, Qmake will generate pro files. In addition, you can add the following options in this mode:

• R Qmake will traverse the directory

nopwd Qmake will ignore your current working directory's source code file and go to use the specified file in this mode. The files variable can be a list of files or directories if a directory is specified, it will be included in the Dependpath variable. The relevant code in the directory will be included in the generated project file. If the file is given, it will be added to the correct variable, which depends mainly on their extension (suffix name); For example, the. ui file is added to FORMS (Qt2 is interfaces bar),

The. cpp file is added to the SOURCES. In this mode. You can also pass the task to the command line, and when you do, these tasks will be placed after the pro file is generated.

Typically, you generate the. Pro file in project mode first, and then the. Pro file Qmake once to build the makefile.

Http://www.cnblogs.com/bingcaihuang/archive/2010/12/03/1895675.html

Qmake understand (you can also join Lex yacc files)

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.