Qt .pro文件 qmake常用參數

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 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章