Configuration Features
qmake can be set up with extra configuration features that are specified in feature (.prf) files. These extra features often provide support for custom tools that are used during the build process. To add a feature to the build process, append the feature name (the stem of the feature filename) to the CONFIG variable.
For example, qmake can configure the build process to take advantage of external libraries that are supported by pkg-config, such as the D-Bus and ogg libraries, with the following lines:
CONFIG += link_pkgconfig
PKGCONFIG += ogg dbus-1
常用命令参数
HEADERS += hello.h //工程包含头文件
SOURCES += hello.cpp //工程包含的源文件
qmake -o Makefile hello.pro //生成makefile文件
qmake -tp vc hello.pro //生成vs文件
QMAKE_CXXFLAGS += -Wno-unused-parameter -Wno-unused-variable //取消没有使用参数警告
QMAKE_CXXFLAGS += -fno-exceptions //设置没有异常
QMAKE_RESOURCE_FLAGS += -compress 9 -threshold 0 //设置资源文件的压缩等级
编译文件存放位置
OBJDIR = obj_temp
UI_DIR = $$OBJDIR/ui
RCC_DIR = $$OBJDIR/rcc
MOC_DIR = $$OBJDIR/moc
OBJECTS_DIR = $$OBJDIR/obj
国际化翻译
# For autocompiling qm-files.
TRANSLATIONS = translations/zh.ts \
translations/uk.ts
#rules to generate ts
QMAKE_LUPDATE = $$[QT_INSTALL_BINS]/lupdate.exe
#limitation: only on ts can be generated
updatets.name = Creating or updating ts-files...
updatets.input = _PRO_FILE_
updatets.output = $$TRANSLATIONS
updatets.commands = $$QMAKE_LUPDATE ${QMAKE_FILE_IN}
updatets.CONFIG += no_link no_clean
QMAKE_EXTRA_COMPILERS += updatets
#rules for ts->qm
isEmpty(QMAKE_LRELEASE) {
win32: QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease.exe
else: QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
}
updateqm.name = Compiling qm-files...
updateqm.input = TRANSLATIONS
updateqm.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm
updateqm.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm
updateqm.CONFIG += no_link no_clean target_predeps
QMAKE_EXTRA_COMPILERS += updateqm
# Release all the .ts files at once
updateallqm = $$QMAKE_LRELEASE -silent $$TRANSLATIONS
调用文件中的命令
# Rules for creating/updating {ts|qm}-files
include(translations/i18n.pri)
# Build all the qm files now, to make RCC happy
system($$fromfile(translations/i18n.pri, updateallqm))
pkgconfig
CONFIG += link_pkgconfig
PKGCONFIG += ogg dbus-1 (/usr/lib/x86_64-linux-gnu/pkgconfig)
使用静态和动态链接
LIBS += -Wl,-Bstatic
LIBS += -Wl,-Bdynamic