KS02-04 pro common configuration file

Copyright Notice

----------------------------------------------------------------

Author: White old daughter named

Please indicate the source!

Web version Course Source extraction code: 1uy7


introduction

----------------------------------------------------------------

In the previous section we introduce the basic configuration pro exe files with a single example, this section look at some common configuration pro file.

 

text

----------------------------------------------------------------

1.    EXE or dll --- TEMPLATE

We have developed a program either program exe, dll either program, which is determined by what it? First, let's introduce TEMPLATE configuration items. The configuration item to determine our program is generated exe or dll.

TEMPLATE = app # represents the item to generate a exe

TEMPLATE = lib # represents the item to generate a dll.

TEMPLATE = subdirs # indicates that this item will scan the specified subdirectory and perform a set of related operations.

                       # Often used in conjunction with SUBDIRS parameters.

                       # For example, when you specify a list of subdirectories to be translated, you can use the configuration.

 

2.    What does the development of language --- LANGUAGE

Syntax: LANGUAGE = C ++

This project represents a development with C ++ language.

Note: C capitalized.

 

3.    generation module name --- TARGET

Syntax: TARGET = xxx

This project represents the name of the program generated as xxx.

For example, according TEMPLATE parameter, if produced on a WINDOWS or Prog.dll prog.exe, or LINUX is generated on the prog (exe filename) or libprog.so.1.0.0 (dll file name), can be used :

TARGET= prog

 

4.    Debug or release --- CONFIG

Grammar: CONFIG + = xxx xxx xxx

Some CONFIG configuration item indicates an increase, with an intermediate space distinguished.

Grammar: CONFIG - = xxx xxx xxx

CONFIG configuration means to delete certain items.

Common parameters introduced:

release

Constructing release version. If you also specify debug, the last one will work. + Can be controlled by such CONFIG - = release, CONFIG + = release

debug

Construction of the project in debug mode. It can be controlled by +/-.

debug_and_release

Construction of the project to debug and release modes. Simultaneously generate debug release version of the target program that is a compile-time.

precompile_header

You can use precompiled headers in the project.

rt

Enable RTTI support. The default compiler defaults (with the specific compiler about). Close by rtti_off.

size

Enable STL support. The default compiler defaults (with the specific compiler about). Close by stl_off.

thread

Enabling thread support. When enabled CONFIG including qt. thread is the default setting.

warn_on

The compiler should output as many warnings. If you also specify the warn_off, the last one will work.

warn_off

The compiler should output as few warnings.

qt

He expressed the need to link qt libraries. Generally require the use of the Qt library configuration items, the development of the service module, if only using Qt's pro file to organize and compile the project, generally use other libraries or library to write their own, so when writing service module generally do not qt ( wrote: CONFIG - = qt).

c++11

Enabling c ++ 11 support. If the compiler does not support this option c ++ 11, it has no effect. Not supported by default c ++ 11.

c++14

启用c++14支持。如果编译器不支持c++14这个选项,没有影响。默认不支持c++14。

 

5.   使用qt的哪些模块---QT

语法:QT +=  xxx  xxx xxx

表示增加某些QT配置项,各个配置项之间用空格隔开。

语法:QT -=  xxx  xxx xxx

表示删除某些QT配置项。

指定项目中使用Qt的模块。默认情况下,QT包含core和gui这两个模块,以确保标准的GUI应用程序无需进一步的配置就可以构建。

如果想建立一个不包含Qt GUI模块的项目,可以使用“ -=”操作符。

下面一行将构建一个不带gui的Qt项目:

1.    

QT  -=    gui  # 仅仅使用core模块

如果要创建一个界面(widget),而且要用到XML及网络相关的类,那么需要包含如下模块:

1.    

QT +=   widgets xml network

请注意,如果您需要用到ui文件,请务必配置QT+= widgets,否则编译时将无法通过uic处理ui文件(无法生成ui文件对应的.h头文件),将导致编译失败。

 

6.   各种DIR | 各种PATH

DEPENDPATH

指定查看解决依赖关系的目录列表,当包含文件时使用:

1.    

DEPENDPATH   += .  forms include  qrc    sources

其中"."表示当前目录。

INCLUDEPATH

指定编译项目时应该被搜索的include目录,比如:

1.    

INCLUDEPATH   = $$(TRAINDEVHOME)/include

这里使用了环境变量TRAINDEVHOME,引用环境变量时要写成$$(TRAINDEVHOME)的样子。关于环境变量的使用将在下节详细介绍。

这里需要注意的是,如果项目中包含资源 (.ui) 文件,那么应该将$$UI_DIR添加到INCLUDEPATH中,这需要提前定义UI_DIR的值:

1.      

2.      

3.      

UI_DIR = $(TRAINDEVHOME)/obj/demo/dialog/ui

INCLUDEPATH   += $$(TRAINDEVHOME)/include \

                 $$UI_DIR

 

DESTDIR:

指定目标文件的存放位置,也就是项目生成的exe或dll的存放目录。 比如下述语句指明了一个dll项目的目标程序的存放位置:

1.    

DESTDIR   = ../../lib

 

MOC_DIR:

指定来自moc的所有中间文件放置的目录(含Q_OBJECT宏的头文件转换成标准.h文件的存放目录)。比如:

1.    

MOC_DIR   = $$(TRAINDEVHOME)/obj/moc

   

OBJECTS_DIR:

指定所有中间文件.o(.obj)的存放目录,比如:

1.    

OBJECTS_DIR   = $$(TRAINDEVHOME)/obj/chapter02/ks02_04

 

RCC_DIR:

指定Qt资源编译器输出文件的目录(.qrc文件转换成qrc_*.h文件的存放目录),比如:

1.    

RCC_DIR   =$$(TRAINDEVHOME)/obj/chapter02/ks02_04/resources

 

UI_DIR:

指定qt的uic命令转换ui文件得到的所有中间文件放置的目录(.ui文件转化成ui_*.h文件的存放目录),比如:

1.    

UI_DIR   =$$(TRAINDEVHOME)/obj/chapter02/ks02_04/ui

 

7.   FORMS

指定项目使用的ui文件。这些ui文件在编译前将被qt的uic命令处理。所有的构建这些ui文件所需的依赖、头文件和源文件都会自动被添加到项目中。

1.      

2.      

FORMS   = mydlg.ui \

        login.ui

 

8.   HEADERS

指定项目用到的文件,比如:

1.      

2.      

3.      

4.      

HEADERS   = abc.pro \

          myfile.h \

          ../../comdll/mycom.h \

          $$(TRAINDEVHOME)/include/base.h

注:

1.     将pro文件添加到HEADERS是为了方便,这样就可以在VisualStudio工具中直接找到pro文件,而无需到资源管理器查找。

2.     可以用相对路径的语法,比如:../../comdll/mycom.h

3.     可以使用环境变量,比如: $$(TRAINDEVHOME)/include/base.h

4.     使用”\”进行换行。"\"前加一个空格。

 

9.   SOURCES

项目用到的cpp文件,语法、注意点同HEADERS。

 

10.  RESOURCES

项目用到的资源文件 (qrc) 的名称,比如:

1.    

RESOURCES   += mdi.qrc

 

11.  LIBS

指定链接到项目中的库列表。使用-l(小写的L)和-L两种语法。

-l(小写的L)

表示库文件名,比如,下面的语句表示链接到库文件mycomm。

1.    

LIBS  += -lmycomm

 

-L

表示库文件所在的路径,比如,下面的语句表示库文件所在目录为:

/usr/local/myprogram/lib,链接的库文件为mycomm、fesp。

1.      

2.      

3.      

LIBS  += -L/usr/local/myprogram/lib \

                        -lmcomm \

                        -lfesp

       

12.  TRANSLATIONS

指定包含用户界面翻译文本的翻译(.ts)文件列表,比如:

         #xxxfortranslations.pro

1.    

TRANSLATIONS =translations/graphplatform_zh_CN.ts

     该配置将被lupdate命令读取(如下,手工执行该命令),生成的ts文件就保存在TRANSLATIONS所指向的文件名。

lupdate   xxxfortranslations.pro 

 

13.  SUBDIRS

  同template=subdirs配合使用。

  该配置指出本项目包含的子目录,可以用来扫描生成翻译文件,或者级联生成整个项目的Makefile。

1.      

2.      

3.      

4.      

5.      

6.      

7.      

template=subdirs

 

SUBDIRS    = \

            esfc   \

            common \

            phcore \

            phwidget

如果pro包含上述内容,那么对该pro执行qmake时,qt会自动进入SUBDIRS所包含的各个子目录,分别执行qmake。

 

注:

1.   修改pro或pri文件后,务必重新执行qmake或qmake –tp vc,以便更新Makefile或者VisualStudio的项目文件(.vcxproj)

 

结语

----------------------------------------------------------------

本节,我们给大家介绍了pro文件常用的一些配置,内容稍微有点多。读者需要通过多加练习慢慢掌握。练习时,读者可以尝试修改配置项的值通过观察效果来加深理解。


----------------------------------------------------------------

《Qt入门与提高-GUI产品开发》目录请添加链接描述
上一节:K02-03加点料-增加一张图片
下一节:

Guess you like

Origin blog.51cto.com/14038054/2434538