Qt 如何自动安装常用依赖?

使用 *.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/

转载于:https://www.cnblogs.com/cheungxiongwei/p/10449436.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值