2.1 工程配置文件
QTCreator中有4种配置文件:pro、pri、prf、prl
2.1.1 pro
注释:#
1. QT
QT += core gui sql xml 加载core gui、sql和xml库。
2.TEMLATE
TEMPLATE = app 项目类型为application
TEMPLATE = lib 项目类型为Library
3.临时文件位置指定
MOC_DIR = temp/moc #指定moc命令将含Q_OBJECT的头文件转换成标准.h文件的存放目录
RCC_DIR = temp/rcc #指定rcc命令将.qrc文件转换成qrc_*.h文件的存放目录
UI_DIR = temp/ui #指定rcc命令将.qrc文件转换成qrc_*.h文件的存放目录
OBJECTS_DIR = temp/obj #指定目标文件(obj)的存放目录
4.get shadow build path
$$shadowed($$PWD)
4.$$
查看完整路径:message(***), eg:message($$PWD)
$$PWD .pro的路径
$$OUT_PWD 输出文件路径
$$_PRO_FILE_ 正在使用的pro文件路径
$$_PRO_FILE_PWD_ 正在使用的pro文件目录
6.CONFIG
指定编译器选项和项目配置,值由qmake内部识别并具有特殊意义。以下配置值控制编译标志:
选项 | 说明 |
release | 项目以release模式构建。如果也指定了debug,那么最后一个生效。 |
debug | 项目以debug模式构建。 |
debug_and_release | 项目准备以debug和release两种模式构建。 |
debug_and_release_target | 此选项默认设置。如果也指定了debug_and_release,最终的debug和release构建在不同的目录。 |
build_all | 如果指定了debug_and_release,默认情况下,该项目会构建为debug和release模式。 |
autogen_precompile_source | 自动生成一个.cpp文件,包含在.pro中指定的预编译头文件。 |
ordered | 使用subdirs模板时,此选项指定应该按照目录列表的顺序处理它们。 |
precompile_header | 可以在项目中使用预编译头文件的支持。 |
warn_on | 编译器应该输出尽可能多的警告。如果也指定了warn_off,最后一个生效。 |
warn_off | 编译器应该输出尽可能少的警告。 |
exceptions | 启用异常支持。默认设置。 |
exceptions_off | 禁用异常支持。 |
rtti | 启用RTTI支持。默认情况下,使用编译器默认。 |
rtti_off | 禁用RTTI支持。默认情况下,使用编译器默认。 |
stl | 启用STL支持。默认情况下,使用编译器默认。 |
stl_off | 禁用STL支持。默认情况下,使用编译器默认。 |
thread | 启用线程支持。当CONFIG包括qt时启用,这是缺省设置。 |
c++11 | 启用c++11支持。如果编译器不支持c++11这个选项,没有影响。默认情况下,支持是禁用的。 |
c++14 | 启用c++14支持。如果编译器不支持c++14这个选项,没有影响。默认情况下,支持是禁用的。 |
7.DESTDIR 指定放置目标文件的位置
DESTDIR = ../../lib
2.1.2 pri
i 是include的首字母。类似于C、C++中的头文件,可以把 *.pro 文件内的一部分单独放到一个 *.pri 文件内,然后包含进来,这样就可以实现过个pro共用pri的一些特性或实现项目拆分。
pro中包含pri:include(propriprfprl.pri)
2.1.3 prf
f是特性feature的首字符,和pri文件类似,该文件也是要被包含进pro文件的,只是它更隐蔽。
如:CONFIG+=QT
当我们在CONFIG中指定一个东西时,qmake就会尝试去加载相应的feature文件:Qt安装目录下的 mkspecs/features/qt.prf
features 文件的文件名必须小写,qmake 去哪些目录下搜索features文件呢?首先是$$QTDIR /mkspecs/features,其次,可以在工程根目录里添加.qmake.conf文件,这样就可以读取根目录下/mkspecs/features里的prf文件了。加载prf(这里假设为mytest.prf)文件有两种方式:
(1)CONFIG += mytest
(2)load(mytest)
2.1.4 prl
l 是链接(link)的首字符。主要和生成与使用静态库密切相关(动态库也可以有该文件,去Qt安装目录下的lib目录下看看即可)。
生成静态库时,我们需要使用下列配置(进而生成和库文件同名的 *.prl 文件)
CONFIG += create_prl
当工程的TEMPLATE为app时,会自动添加如下指令(找库文件的时候,会尝试找相应的 *.prl 文件)
CONFIG += link_pri
那么该文件有什么用处呢?举一个大家可能熟悉的例子QextSerialPort1.2这个库(windows下的情况):
编译时,需要 setupapi.lib advapi32.lib user32.lib 这几个库文件
编译成静态库以后,它本身是不包含这3个库文件信息的
于是,当我们使用这个 QextSerialPort 静态库,还是需要指定 这几个库文件
如果有prl文件呢,该文件就会包含依赖信息了,我们看一下:
QMAKE_PRL_BUILD_DIR = E:/dbzhang800-qextserialport/buildlib
QMAKE_PRO_INPUT = buildlib.pro
QMAKE_PRL_TARGET = qextserialport-1.2
QMAKE_PRL_CONFIG = include_source_dir incredibuild_xge lex yacc warn_on uic resources incremental_off windows release ReleaseBuild Release build_pass qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe stl exceptions rtti mmx 3dnow sse sse2 release ReleaseBuild Release build_pass qt qextserialport-buildlib create_prl qextserialport-uselib qextserialport-static static debug_and_release build_all release ReleaseBuild Release build_pass no_autoqmake staticlib static moc thread
QMAKE_PRL_LIBS = setupapi.lib advapi32.lib user32.lib d://Qt//4.7.0//lib//QtGui4.lib d://Qt//4.7.0//lib//QtCore4.lib
2.2 自动注释
qtcreator->工具->文本编辑器-snippets
hfile
/*******************************************************************************
*
* Copyright (C) 2019-2029, Moemil Lab
* File name: %{CurrentDocument:FileName}
* Author:dengbaigao Date: %{CurrentDate:yyyy-MM-dd} %{CurrentTime: H:m:s}
* Version: 1.0.001
* Description: $null$
* Others: $null$
* History:
*
* denghao %{CurrentDate:yyMMdd} 1.0.001 create
*
*******************************************************************************/
hmethod
/*******************************************************************************
*
* function Name: $name$
* description: $null$
* input parameters:
* @param1: describe param1
* @param2: describe param2
* output parameters:
* @param1: describe param1
* @param2: describe param2
* return value: int - describe int
* Author: dengbaigao
* Create Time: %{CurrentDate:yyyy-MM-dd} %{CurrentTime: H:m:s}
* other instructions: null
* modify information: null
*
*******************************************************************************/
内部变量:
%{#:
%{Config:DefaultProjectDirectory}
%{Config:LastFileDialogDirectory}
%{Cpp:LicenseTemplate}
%{Cpp:LicenseTemplatePath:FileBaseName}
%{Cpp:LicenseTemplatePath:FileName}
%{Cpp:LicenseTemplatePath:FilePath}
%{Cpp:LicenseTemplatePath:NativeFilePath}
%{Cpp:LicenseTemplatePath:NativePath}
%{Cpp:LicenseTemplatePath:Path}
%{CurrentBuild:Env:}
%{CurrentBuild:Name}
%{CurrentBuild:Type}
%{CurrentDate:}
%{CurrentDate:ISO}
%{CurrentDate:Locale}
%{CurrentDate:RFC}
%{CurrentDevice:HostAddress}
%{CurrentDevice:PrivateKeyFile}
%{CurrentDevice:SshPort}
%{CurrentDevice:UserName}
%{CurrentDocument:Column}
%{CurrentDocument:ColumnCount}
%{CurrentDocument:FileBaseName}
%{CurrentDocument:FileName}
%{CurrentDocument:FilePath}
%{CurrentDocument:FontSize}
%{CurrentDocument:NativeFilePath}
%{CurrentDocument:NativePath}
%{CurrentDocument:Path}
%{CurrentDocument:Row}
%{CurrentDocument:RowCount}
%{CurrentDocument:Selection}
%{CurrentDocument:XPos}
%{CurrentDocument:YPos}
%{CurrentKit:FileSystemName}
%{CurrentKit:Id}
%{CurrentKit:Name}
%{CurrentProject:BuildPath}
%{CurrentProject:FileBaseName}
%{CurrentProject:FileName}
%{CurrentProject:FilePath}
%{CurrentProject:Name}
%{CurrentProject:NativeFilePath}
%{CurrentProject:NativePath}
%{CurrentProject:Path}
%{CurrentProject:QT_HOST_BINS}
%{CurrentProject:VcsName}
%{CurrentProject:VcsTopLevelPath}
%{CurrentProject:VcsTopic}
%{CurrentRun:Executable:FileBaseName}
%{CurrentRun:Executable:FileName}
%{CurrentRun:Executable:FilePath}
%{CurrentRun:Executable:NativeFilePath}
%{CurrentRun:Executable:NativePath}
%{CurrentRun:Executable:Path}
%{CurrentRun:Name}
%{CurrentTime:}
%{CurrentTime:ISO}
%{CurrentTime:Locale}
%{CurrentTime:RFC}
%{Env:}
%{HostOs:ExecutableSuffix}
%{HostOs:PathListSeparator}
%{HostOs:isLinux}
%{HostOs:isOSX}
%{HostOs:isUnix}
%{HostOs:isWindows}
%{IDE:ResourcePath}
%{JS:}
%{Session:FileBaseName}
%{Session:FileName}
%{Session:FilePath}
%{Session:Name}
%{Session:NativeFilePath}
%{Session:NativePath}
%{Session:Path}
%{UUID}