qmake介绍
只需要在.pro文件写入几行配置信息,qmake工具就能自动生成Makefile文件。qmake包含支持Qt开发的附加特性,包含moc和uic的构建规则,qmake还可以为Microsoft Visual studio生成项目,且不需要开发人员更改项目文件。
qmake使用
生成Makefile:qmake -o Makefile hello.pro
生成VS项目文件:qmake -tp vc hello.pro
生成Xcode项目文件:qmake -spec macx-xcode hello.pro
设置属性-值:qmake -set property value
查询属性:qmake -query property
.pro写法
#要使用的Qt模块
QT += network xml
#要构建的项目类型
TEMPLATE = app
#输出程序名称
TARGET = myapp
#程序输出目录
DESTDIR = ./mybin
#配置:包含调试信息
CONFIG += debug
#定义宏
DEFINES += MY_STUFF
#头文件
HEADERS += hello.h
#源文件
SOURCES += hello.cpp \
main.cpp
#外部头文件
INCLUDEPATH = c:/msdev/include d:/stl/include
#链接外部库
LIBS += -L/usr/local/lib -lmath
#win平台
win32 {
SOURCES += hellowin.cpp
}
#unix平台
unix {
SOURCES += hellounix.cpp
}
#win平台并且调试模式(嵌套作用域)
win32:debug {
CONFIG += console
}
#函数举例
eval(TARGET = myapp) {
message($$TARGET)
}
options = $$find(CONFIG, "debug") $$find(CONFIG, "release")
count(options, 2) {
message(Both release and debug specified.)
}
!exists( main.cpp ) {
error( "No main.cpp file found" )
}
qmake语法
#赋值:=
TARGET = app
#追加:+=
DEFINES += MY_STUFF
#移除:-=
D