我正在尝试使用 windeployqt.exe
(Qt 5.13.2) 为 CMake 3.16 生成的调试应用程序部署 dll。除了平台插件 dll 部署了 qwindows.dll
之外,所有 dll 都部署正确。而不是 qwindowsd.dll
并在我尝试运行可执行文件时导致以下错误:
This application failed to start because no Qt platform plugin could be initialized.
到目前为止,我已经尝试过:
--debug
在 windeployqt
命令行。那失败了,因为 Qt5Coredd.dll
找不到(注意双 d)。 PATH
确保它不包含任何带有 platforms
的文件夹目录。 如果我复制
qwindowsd.dll
手动,一切正常。但是我真的很想弄清楚我做错了什么windeployqt
.
最佳答案
这显然是 Qt 拖延修复的一个已知问题,但我在 CMake 中找到了一个解决方法 - 这适用于 Ninja 生成器/Visual Studio 的内置 CMake 支持以及常规的 Visual Studio 解决方案生成器
# 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()
关于c++ - windeployqt 不会为调试应用程序部署 qwindowsd.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59828611/