c++ - windeployqt 不会为调试应用程序部署 qwindowsd.dll

标签 c++ qt qt5

我正在尝试使用 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.



到目前为止,我已经尝试过:
  • 指定 --debugwindeployqt命令行。那失败了,因为 Qt5Coredd.dll找不到(注意双 d)。
  • 验证没有设置 Qt 插件相关的环境变量。
  • 已查 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/

    相关文章:

    c++ - 如何在不关闭正在运行的程序的情况下平滑重启c++程序?

    c++ - 计算机视觉系统中机械臂的 Controller

    android - 如何防止 Gradle/Android Studio 覆盖 CMake 提供的 C++ 编译器设置?

    qt qml。 MouseArea 可以看到事件,但将它们全部传递给父级而不影响它们吗?

    c++ - 使用组合框在qt对话框中切换不同的表

    c++ - dynamic_cast 被引入 C++ 以破坏多态性?

    c++ - 关闭 MainWindow 后 Qt 应用程序仍在运行

    c++ - QSqlite 在 Windows 和 Linux 上的不同行为

    c++ - QDataStream成员间分配

    c++ - 如何监控Qt主队列长度?