vscode+qt开发环境配置
vscode + qt 实现代码提示 i3两外两个桌面 打开qt的 ui设计 designer 和文档 assiant 实现高效率开发
这个方法首先需要用qtcreat创建好项目
注:本文适用linux系统用户,windwos用户自行根据配置改动
.vscode 文件夹放四个文件
- c_cpp_properties.json 代码提示
- tasks.json 编译配置
- build.sh 编译脚本 配合task.json使用
- launch.json F5 运行代码
代码提示
需要提前装好插件 C++ Intellisense(插件商店搜c++)
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/lib/x86_64-linux-gnu/**", //qt动态库路径 qt版本不同 名字有些许差异 自动更改
"/usr/include/x86_64-linux-gnu/qt5/**" //qt动态库路径 qt版本不同 名字有些许差异 自动更改
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
编译配置
vscode 编译快捷键 ctrl+shift+b
也可使用shell手动编译
toolkit cmake项目: cmake make
toolkit qmake项目: qmake make
效果相同,快捷键需要配置下方文件
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "qmake",
"type": "shell",
"command": "sh",
"args": [
"${workspaceRoot}/.vscode/build.sh",
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
build.sh
qmake #qt配置的cmake的话 这个地方改成cmake
make
运行配置
下方配置 适合习惯用快捷键 F5 调试的用户,我更习惯用terminal直接运行可执行文件
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out", //根据生成的执行文件名自行更改
"args": [
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
其他
我的习惯
生成makefile : qmake 或者 cmake
编译: make
ui设计: 单独打开一个i3工作区放ui设计界面,打开终端(win/super+enter), designer xxx.ui
单开一个工作区放qt文档:win/super+d assistant
本人习惯用终端编译运行,所以对我来说最有用的是代码提示配置文件 c_cpp_properties.json
我这里生成好了一个.vscode文件,直接放到qt项目,改吧改吧就能用了:git clone https://gitee.com/dspure/vscode-qt.git