Qt6 安装后出现编译正常,直接运行出问题

问题描述:

 新建 mainWindows桌面工程,直接编译,编译正常.然后 ctrl+R运行程序:

 直接crashed.  提示一下错误:

qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Qt安装路径动过 可能是路径问题猜测,根据网上帖子搜索参考  复制依赖方法.

尝试方法:

在pro文件加入下面代码:

## 加入pro文件,编译后自动复制依赖库进入编译后的目录
contains(CONFIG, static){
    # Static compilation does not require deployment
}else{
    # Windows platform(only for x86 architecture)
    win32 {
        DEPLOY_TOOL = $${dirname(QMAKE_QMAKE)}/windeployqt.exe
        DEPLOY_TOOL = $$replace(DEPLOY_TOOL, /, \\)

        contains(CONFIG, debug, debug|release){
            DEPLOY_TARGET = $${OUT_PWD}/debug/$${TARGET}.exe
        }else{
            DEPLOY_TARGET = $${OUT_PWD}/release/$${TARGET}.exe
        }

        DEPLOY_TARGET=$$replace(DEPLOY_TARGET, /, \\)
        msvc {
            QMAKE_POST_LINK+=$${DEPLOY_TOOL} $${DEPLOY_TARGET} --force --no-translations $$escape_expand(\\n)
        }else{
            QMAKE_POST_LINK+=$${DEPLOY_TOOL} $${DEPLOY_TARGET} --force --no-translations $$escape_expand(\\n\\t)
        }

        CONFIG(debug, debug|release){
            DEPLOY_TARGET_PATH = $$OUT_PWD/debug/
        }
        CONFIG(release, debug|release){
            DEPLOY_TARGET_PATH = $$OUT_PWD/release/
        }
    }
}

重新编译代码,ctrl+R运行,程序正常跑起来了.

上述代码解释,主要是复制依赖进入编译后的目录,相当于发布程序了.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值