【解决】Qt Creator只显示.pro文件 / Cannot run compiler 'cl'.

问题:在Qt Creator创建项目时,成功创建了项目,但QtCreator只显示.pro文件,并且无法构建。

编译输出:

Project ERROR: Cannot run compiler 'cl'. Output:

=================== ===================

Maybe you forgot to setup the environment?

15:00:43: The command "D:\Software\Qt\5.15.2\msvc2019_64\bin\qmake.exe D:\code\QtProjects\untitled2\untitled2.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"" terminated with exit code 3.

15:00:43: Error while building/deploying project untitled2 (kit: Desktop Qt 5.15.2 MSVC2019 64bit)

15:00:43: When executing step "qmake" Issue: :-1: error: Cannot run compiler 'cl'. Output:

版本信息: Qt 5.12.5, Qt Creator 17.0.0, Windows 11, 编译器MSVC2019_64bit

尝试过但无用的方法:重装Qt、Qt Creator、VS2019、配置cl.exe的环境变量……

解决方法:

MSVC 编译器需要特殊的环境变量(如INCLUDE等),这些变量通常由 VS 的命令行工具自动配置。

  • 按下Win + S,搜索并打开 “x64 Native Tools Command Prompt for VS 2019”(64 位工具链)。
  • 在命令行中输入 Qt Creator 的安装路径并启动(例如):
    D:\Software\Qt\Tools\QtCreator\bin\qtcreator.exe
     
  • 用这种方式启动后,尝试重新打开项目并构建。如果能正常编译,说明问题出在环境变量配置上。
  • 将D:\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat 所在的路径添加到环境变量,即可解决问题。
posted @ 2025-07-31 16:15  明日未来  阅读(300)  评论(0)    收藏  举报