简体   繁体   English

使用Visual Studio运行Qt CMake个项目

[英]Using Visual Studio to run Qt CMake projects

I'm using Visual Studio 2019 to build a CMake project that uses Qt. Visual Studio natively supports CMake, so integrating it with Qt I just modified the CMakeSettings.json file by adding a globa variable as follows:我正在使用 Visual Studio 2019 构建一个使用 Qt 的 CMake 项目。Visual Studio 本机支持 CMake,因此将其与 Qt 集成 我刚刚通过添加 globa 变量修改了 CMakeSettings.json 文件,如下所示:

      "variables": [
        {
          "name": "CMAKE_PREFIX_PATH",
          "value": "path_to_qt_installation",
          "type": "STRING"
        }
      ]

This directs CMake to correctly find the Qt libraries and builds the project successfully.这会指示 CMake 正确找到 Qt 库并成功构建项目。 However when trying to run the project, Visual Studio cannot find the Qt dll and link them to the executable:但是,当尝试运行该项目时,Visual Studio 找不到 Qt dll 并将它们链接到可执行文件:

The code execution cannot proceed because Qt5Qml.dll was not found.代码执行无法继续,因为找不到 Qt5Qml.dll。 Reinstalling the program may fix this problem.重新安装程序可能会解决此问题。

To solve this problem, I can manually run windeployqt.exe inside the build directory and then run the program.为了解决这个问题,我可以在构建目录中手动运行windeployqt.exe ,然后运行程序。 This solves the issue, however I would like to avoid this and would like Visual Studio to find the Qt dll files automatically.这解决了问题,但我想避免这种情况,并希望 Visual Studio 自动查找 Qt dll 文件。 Qt Creator on Windows does this by default, so I would like the same experience with VS 2019. What is the correct to solve this issue? Qt Windows 上的 Creator 默认执行此操作,所以我希望与 VS 2019 有相同的体验。解决此问题的正确方法是什么?

If the DLL is not in the same folder as the executable, Windows will search for the file in the folder specified in the system path.如果 DLL 与可执行文件不在同一个文件夹中,Windows 将在系统路径中指定的文件夹中搜索文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM