我试图使用windeployqt.exe (QT5.13.2)为CMake 3.16生成的调试应用程序部署dll。除了平台插件dll之外,所有dll都被正确部署,后者部署qwindows.dll而不是qwindowsd.dll,并在尝试运行可执行文件时导致以下错误:
这个应用程序启动失败,因为没有Qt平台插件可以初始化。
到目前为止,我已经尝试过:
windeployqt命令行中指定--debug。这失败是因为找不到Qt5Coredd.dll (请注意没有设置与Qt插件相关的环境变量的双重Qt5Coredd.dll。PATH以确保它不包含带有platforms目录的任何文件夹。)
如果我手动复制qwindowsd.dll,一切都正常。不过,我真的很想弄清楚我对windeployqt做错了什么。
发布于 2021-08-31 22:26:48
这显然是Qt在修复过程中遇到的一个已知问题,但我在CMake中找到了一个解决办法--这既适用于忍者生成器/ Visual内置的CMake支持,也适用于常规的Visual解决方案生成器。
# Split windeployqt into 2 parts to fix issue with deploying debug plugins
add_custom_command(TARGET MyApp POST_BUILD
COMMAND ${QT_PATH}/bin/windeployqt --compiler-runtime --no-plugins ${MY_APP_EXE})
if (CMAKE_GENERATOR STREQUAL "Ninja")
# Ninja is a single-config generator so we can use CMAKE_BUILD_TYPE to generate different commands
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command(TARGET MyApp POST_BUILD
COMMAND ${QT_PATH}/bin/windeployqt --debug --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
else()
add_custom_command(TARGET MyApp POST_BUILD
COMMAND ${QT_PATH}/bin/windeployqt --release --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
endif()
else()
# if in MSVC we have to check the configuration at runtime instead of generating different commands
add_custom_command(TARGET MyApp POST_BUILD
COMMAND cmd.exe /c if "$(Configuration)" == "Debug" ${QT_PATH}/bin/windeployqt --debug --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
add_custom_command(TARGET MyApp POST_BUILD
COMMAND cmd.exe /c if not "$(Configuration)" == "Debug" ${QT_PATH}/bin/windeployqt --release --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
endif()https://stackoverflow.com/questions/59828611
复制相似问题