使用 *.prf 文件自动安装依赖
在 Qt\Qt5.9.5\5.9.5\msvc2015\mkspecs\features
路径中添加 auto_install.prf
文件
然后在程序配置文件(*.pro)中添加CONFIG += auto_install
程序编译完成时,则会自动执行 auto_install.prf
文件中的内容,这样避免了每次都要写配置文件的麻烦
auto_install.prf
文件内容如下:
# 自动复制依赖
CONFIG(debug,debug | release){
QT_BIN_FILES += \
$$[QT_INSTALL_BINS]/Qt5Cored.dll \
$$[QT_INSTALL_BINS]/Qt5Guid.dll \
$$[QT_INSTALL_BINS]/Qt5Widgetsd.dll \
$$[QT_INSTALL_BINS]/Qt5Networkd.dll \
$$[QT_INSTALL_BINS]/Qt5Sqld.dll
QT_BIN_PATH = $$OUT_PWD/debug/
win32 {
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c copy /y $$shell_path($$var) $$shell_path($$QT_BIN_PATH) $$escape_expand(\\n\\t))
}
}
unix {
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cp $$var $$QT_BIN_PATH $$escape_expand(\\n\\t))
}
}
QT_PLATFORMS_BIN_FILES += \
$$[QT_INSTALL_PLUGINS]/platforms/qwindowsd.dll
QT_PLATFORMS_BIN_PATH = $$OUT_PWD/debug/platforms/
win32 {
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c xcopy /y $$shell_path($$var) $$shell_path($$QT_PLATFORMS_BIN_PATH) $$escape_expand(\\n\\t))
}
}
unix {
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cp $$var $$QT_PLATFORMS_BIN_PATH $$escape_expand(\\n\\t))
}
}
}else{
QT_BIN_FILES += \
$$[QT_INSTALL_BINS]/Qt5Core.dll \
$$[QT_INSTALL_BINS]/Qt5Gui.dll \
$$[QT_INSTALL_BINS]/Qt5Widgets.dll \
$$[QT_INSTALL_BINS]/Qt5Network.dll \
$$[QT_INSTALL_BINS]/Qt5Sql.dll
QT_BIN_PATH = $$OUT_PWD/release/
win32 {
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c copy /y $$shell_path($$var) $$shell_path($$QT_BIN_PATH) $$escape_expand(\\n\\t))
}
}
unix {
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cp $$var $$QT_BIN_PATH $$escape_expand(\\n\\t))
}
}
QT_PLATFORMS_BIN_FILES += \
$$[QT_INSTALL_PLUGINS]/platforms/qwindows.dll
QT_PLATFORMS_BIN_PATH = $$OUT_PWD/release/platforms/
win32 {
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c xcopy /y $$shell_path($$var) $$shell_path($$QT_PLATFORMS_BIN_PATH) $$escape_expand(\\n\\t))
}
}
unix {
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cp $$var $$QT_PLATFORMS_BIN_PATH $$escape_expand(\\n\\t))
}
}
}
#export(QMAKE_POST_LINK)
jom.exe INSTALL
CONFIG(debug,debug | release){
QT_CORE.path = $$OUT_PWD/debug/
QT_CORE.files = $$[QT_INSTALL_BINS]/Qt5Cored.dll
QT_GUI.path = $$OUT_PWD/debug/
QT_GUI.files = $$[QT_INSTALL_BINS]/Qt5Guid.dll
QT_WIDGETS.path = $$OUT_PWD/debug/
QT_WIDGETS.files = $$[QT_INSTALL_BINS]/Qt5Widgetsd.dll
QT_NETWORK.path = $$OUT_PWD/debug/
QT_NETWORK.files = $$[QT_INSTALL_BINS]/Qt5Networkd.dll
QT_PLATFORMS.path = $$OUT_PWD/debug/platforms/
QT_PLATFORMS.files = $$[QT_INSTALL_PLUGINS]/platforms/qwindowsd.dll
}else{
QT_CORE.path = $$OUT_PWD/release/
QT_CORE.files = $$[QT_INSTALL_BINS]/Qt5Core.dll
QT_GUI.path = $$OUT_PWD/release/
QT_GUI.files = $$[QT_INSTALL_BINS]/Qt5Gui.dll
QT_WIDGETS.path = $$OUT_PWD/release/
QT_WIDGETS.files = $$[QT_INSTALL_BINS]/Qt5Widgets.dll
QT_NETWORK.path = $$OUT_PWD/release/
QT_NETWORK.files = $$[QT_INSTALL_BINS]/Qt5Networkd.dll
QT_PLATFORMS.path = $$OUT_PWD/release/platforms/
QT_PLATFORMS.files = $$[QT_INSTALL_PLUGINS]/platforms/qwindows.dll
}
INSTALLS += QT_CORE QT_GUI QT_WIDGETS QT_NETWORK QT_PLATFORMS
win32 {
CONFIG(debug,debug | release){
QT_BIN_FILES += \
$$[QT_INSTALL_BINS]/Qt5Cored.dll \
$$[QT_INSTALL_BINS]/Qt5Guid.dll \
$$[QT_INSTALL_BINS]/Qt5Widgetsd.dll \
$$[QT_INSTALL_BINS]/Qt5Networkd.dll
QT_BIN_PATH = $$OUT_PWD/debug/
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c copy /y $$shell_path($$var) $$shell_path($$QT_BIN_PATH) $$escape_expand(\\n\\t))
}
QT_PLATFORMS_BIN_FILES += \
$$[QT_INSTALL_PLUGINS]/platforms/qwindowsd.dll
QT_PLATFORMS_BIN_PATH = $$OUT_PWD/debug/platforms/
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c xcopy /y $$shell_path($$var) $$shell_path($$QT_PLATFORMS_BIN_PATH) $$escape_expand(\\n\\t))
}
}else{
QT_BIN_FILES += \
$$[QT_INSTALL_BINS]/Qt5Core.dll \
$$[QT_INSTALL_BINS]/Qt5Gui.dll \
$$[QT_INSTALL_BINS]/Qt5Widgets.dll \
$$[QT_INSTALL_BINS]/Qt5Network.dll
QT_BIN_PATH = $$OUT_PWD/release
for(var, QT_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c copy /y $$shell_path($$var) $$shell_path($$QT_BIN_PATH) $$escape_expand(\\n\\t))
}
QT_PLATFORMS_BIN_FILES += \
$$[QT_INSTALL_PLUGINS]/platforms/qwindows.dll
QT_PLATFORMS_BIN_PATH = $$OUT_PWD/release/platforms
for(var, QT_PLATFORMS_BIN_FILES) {
QMAKE_POST_LINK += $$quote(cmd /c xcopy /y $$shell_path($$var) $$shell_path($$QT_PLATFORMS_BIN_PATH) $$escape_expand(\\n\\t))
}
}
# 详细使用请查看 qt file_copies.prf 文件
#CONFIG *= file_copies
#创建名称以描述要复制的文件:
#COPIES += DocCopyDemo
#在.files成员中列出要复制的文件:
#DocCopyDemo.files = $$files($$PWD/*.pro)
#在.path成员中指定目标路径:
#DocCopyDemo.path = $$OUT_PWD/debug
#(可选)指定要从源路径修剪的基本路径:
#DocCopyDemo.base = $$PWD/