qt中常用工程文件的介绍 .
qt中常用工程文件的介绍 .qmake Common Projects(qmake普通工程)
这章描述怎样去创建基于QT的三种一般工程的工程文件。虽然他们使用许多相同的变量,但是他们中的每一个都有特殊工程的变量用于定制输出文件。
特殊平台的变量不在这描述,对于构建用于mac os x系统的一般二进制文件和处理visual studio文件的问题,建议读者去阅读部署qt应用程序章节。
1.构建一个应用程序
应用程序(app)模板告诉qmake创建一个用于构建一个应用程序的makefile文件。使用这个模板,应用程序的种类可以通过CONFIG变量指定。windows指定这应用程序是一个windows界面程序,consol指定这个应用程序是一个控制台应用程序,这个值仅仅能够在应用程序(app)模板中使用。
应用程序模板中可以使用的变量如下:
HEADERS - A list of all the header files for the application.
SOURCES - A list of all the source files for the application.
FORMS - A list of all the UI files (created using Qt Designer) for the application.
LEXSOURCES - A list of all the lex source files for the application.
YACCSOURCES - A list of all the yacc source files for the application.
TARGET - Name of the executable for the application. This defaults to the name of the project file. (The extension, if any, is added automatically).
DESTDIR - The directory in which the target executable is placed.
DEFINES - A list of any additional pre-processor defines needed for the application.
INCLUDEPATH - A list of any additional include paths needed for the application.
DEPENDPATH - The dependency search path for the application.
VPATH - The search path to find supplied files.
DEF_FILE - Windows only: A .def file to be linked against for the application.
RC_FILE - Windows only: A resource file for the application.
RES_FILE - Windows only: A resource file to be linked against for the application.
2.构建一个库
库(lib)模板告诉qmake创建一个用于构建一个库的makefile文件。使用这个模板的时候,除了应用模板中提到的可以使用的变量外,还可以使用VERSION变量。你可以在工程文件中用这些变量指定关于库的信息。
使用库模板的时候CONFIG可以使用如下值:dll,指明是一个共享库;staticlib,指明是一个静态库;plugin,这个库是一个插件,同时也是一个共享库。
VERSION变量用于指定库的版本号。
库文件的名字是基于平台的。比如,在X11和Mac OS X系统下,库的名字是有前缀lib,但是在windwos下是没有的。
3.构建一个插件
使用lib模板可以构建插件,qmake使用这个模板产生一个makefile文件,使用这个makefile文件产生一个适用于每个平台的不同形式的插件。
4.构建一个设计师插件
qt设计师插件用一组配置构建。可以通过在文件中配置CONFIG变量使能这些设置,
比如:CONFIG += designer plugin
5.在调试模式和发布模式下构建和安装
有些时候,我们必须在两种模式下构建一个工程。虽然CONFIG可以保持debug和release两种选项,但是前者覆盖了后者。
1)为了在两种模式下构建工程,你必须增加debug_and_release选项到CONFIG变量。
CONFIG += debug_and_releaseCONFIG(debug, debug|release) {
TARGET = debug_binary
} else {
TARGET = release_binary
}通过调用make all可以生成两个文件
当配置CONFIG += build_all选项后直接输make则可以构建两种模式下的文件,否则的话默认只构建debug模式下的文件。
2)build_all选项也保证了在安装规则被调用的时候,两个版本的程序都能被安装。
在不同的平台上构建不同的程序名字也是可以的。比如一个库和插件可以按照惯例在不同的平台上命名为不同的名字。
比如在windows和unix下:CONFIG(debug, debug|release) {
mac: TARGET = $$join(TARGET,,,_debug)
win32: TARGET = $$join(TARGET,,d)
}在上面这个片段中,在debug模式下构建程序时将修改构建目标的名称。也可增加else分支,增加在release模式下的特殊处理。
下面在上篇文章中提到的实例中增加本章的一些配置: CONFIG += qt
HEADERS += hello.h
SOURCES += hello.cpp
SOURCES += main.cpp
CONFIG += debug_and_release
CONFIG(debug, debug|release) {
TARGET = hello
} else {
TARGET = hello
}
CONFIG += build_all
CONFIG(debug, debug|release) {
mac: TARGET = $$join(TARGET,,,_debug)
win32: TARGET = $$join(TARGET,,d)
}else{
mac: TARGET = $$join(TARGET,,,_release)
win32: TARGET = $$join(TARGET,,r)
} 谢谢分享
页:
[1]