如何使用VSCode开发Qt项目?
为何使用VSCode开发Qt项目?
因为Qt自带的编辑器丑丑丑…,颜值时代还得是vscode大妹子…
最终效果预览

前期准备
一、环境工具
二、配置系统环境变量
(自行根据自己的Qt安装路径配置)
-
MingW 根目录和bin目录 D:\Qt5\5.15.2\mingw81_64\
D:\Qt5\5.15.2\mingw81_64\bin\
-
cmake.exe D:\Qt5\Tools\mingw810_64\bin\ (cmake.exe)
-
gcc.exe D:\Qt5\Tools\mingw810_64\bin\ (gcc.exe)
效果:

cmd检验:

三、在VSCode配置好扩展CmakeTools里的 Cmake Path

工程实践
一、在非中文路径目录下,创建一个基于MingW / CMake的Qt工程

(注意工程路径不能是中文路径下面,否则编译会出现X fille no found 错误,接下来cmake编译等操作会失败!!!)
在Qt里,Ctrl+R 运行项目
二、VSCode打开该工程目录(CMakeLists.txt所在目录)
-
选择kit : GCC / mingw32 (如果未检测到对应的kit, 请检查以上的环境配置是否正确)

-
F7 构建(Build)项目 -
Shift + F5 运行
若有插件快捷键冲突,点击下面的按钮来操作:

- 成功运行(无报错,弹出程序窗口)

-
测试一下代码提示是否可用 
【总结】可能会出现的报错与解决方法
-
在Qt里报错: ...'QDialog' file not found...
? 原因:工程路径是中文路径…
? 解决:将工程移动/重建于非中文路径下,清理后重新构建运行。
-
在VSCode里: The "cmake" command is not found in PATH. Install it or use `cmake.cmakePath
原因:未进行或配置失败这一步:VSCode配置好扩展CmakeTools里的 Cmake Path
? 解决:检查/配置扩展CmakeTools里的 Cmake Path
|