问题描述:
新建 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运行,程序正常跑起来了.
上述代码解释,主要是复制依赖进入编译后的目录,相当于发布程序了.