以下简称Visual Studio Code为VSCode。
Visual Studio在安装Qt插件后虽然能进行Qt应用开发,但是它本身的体积太大,微软还没有开放Visual Studio单独安装C++开发包的方法。Qt Creator 大版本号仍然停留在4.3上,某些功能迟迟等不来更新和实现,特别是——调试功能。在非用户代码中出现的ASSERT错误,QT Creator不告诉用户代码堆栈,只显示第三方代码哪里ASSERT,让人无语。虽然UI开发、SIGNAL-SLOT的设计仍然由Qt Creator借力,但其它开发工作在VS Code上进行会更让用户省心省力。本文将重点介绍如何用VS Code开发Qt5应用程序。
VSCode本身没有针对Qt应用开发的插件程序,开发工作进行之前务必确保C++开发功能正常。关于VSCode C++开发环境的配置请参考:《VSCode实现C++代码提示、语法高亮、编译和调试》
安装顺序按照以上列出软件的顺序进行。
VSCode开发Qt应用程序比开发单纯的C++程序更简单,因为Qt会自己生成Makefile,免去了用户编译Makefile的烦恼。
Qt所有的平台都有一个类似于Visual Studio中vcvars.bat这样的批处理文件,叫做qtenv2.bat
。它的作用是把当前平台的bin目录加入到应用程序的Path环境变量。打开一个简单的Qt编译命令窗口的代码很简单,代码如下:
@echo off
title qmake and nmake build prompt
set VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
set QTDIR=C:\Qt\Qt5.9.1\5.9.1\msvc2015_64
set PATH=%VCINSTALLDIR%\bin;%QTDIR%\bin;C:\Program Files\7-Zip;%PATH%
call "%VCINSTALLDIR%\vcvarsall.bat" amd64
cmd /k
模板选择是Qt Widgets Application,如下图所示:
Kit Selection去掉其它所有的选择,只留下MSVC2015 X64,如下图所示:
在.vscode文件夹下新建c_cpp_properties.json,代码如下:
{
"version": 3,
"configurations": [{
"name": "msvc2015-x64",
"intelliSenseMode": "msvc-x64",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DLogic",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickScene2D",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtAccessibilitySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtANGLE",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtBluetooth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCharts",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtConcurrent",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDataVisualization",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDeviceDiscoverySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEglSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEventDispatcherSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFbSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFontDatabaseSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtGui",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtHelp",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtLocation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimedia",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaQuick_p",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetwork",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetworkAuth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNfc",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGL",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGLExtensions",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPacketProtocol",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformCompositorSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformHeaders",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPositioning",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPrintSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPurchasing",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQmlDebug",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickControls2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickParticles",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTemplates2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRemoteObjects",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRepParser",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtScxml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSensors",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSql",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSvg",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtThemeSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiPlugin",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiTools",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebChannel",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebSockets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebView",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXmlPatterns",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtZlib",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"${workspaceRoot}"
],
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DLogic",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickScene2D",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtAccessibilitySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtANGLE",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtBluetooth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCharts",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtConcurrent",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDataVisualization",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDeviceDiscoverySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEglSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEventDispatcherSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFbSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFontDatabaseSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtGui",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtHelp",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtLocation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimedia",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaQuick_p",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetwork",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetworkAuth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNfc",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGL",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGLExtensions",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPacketProtocol",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformCompositorSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformHeaders",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPositioning",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPrintSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPurchasing",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQmlDebug",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickControls2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickParticles",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTemplates2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRemoteObjects",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRepParser",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtScxml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSensors",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSql",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSvg",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtThemeSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiPlugin",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiTools",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebChannel",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebSockets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebView",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXmlPatterns",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtZlib",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"${workspaceRoot}"
]
}
}]
}
修改settings.json,确保文件里面至少有以下内容:
"cppcheck.includePaths": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DLogic",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickAnimation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickExtras",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickInput",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DQuickScene2D",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/Qt3DRender",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtAccessibilitySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtANGLE",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtBluetooth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCharts",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtConcurrent",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDataVisualization",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtDeviceDiscoverySupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEglSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtEventDispatcherSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFbSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtFontDatabaseSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtGui",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtHelp",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtLocation",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimedia",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaQuick_p",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtMultimediaWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetwork",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNetworkAuth",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtNfc",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGL",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtOpenGLExtensions",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPacketProtocol",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformCompositorSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPlatformHeaders",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPositioning",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPrintSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtPurchasing",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQmlDebug",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuick",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickControls2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickParticles",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTemplates2",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtQuickWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRemoteObjects",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtRepParser",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtScxml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSensors",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSql",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtSvg",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtTest",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtThemeSupport",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiPlugin",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtUiTools",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebChannel",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineCore",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebEngineWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebSockets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWebView",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtWidgets",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXml",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtXmlPatterns",
"C:/Qt/Qt5.9.1/5.9.1/msvc2015_64/include/QtZlib",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"${workspaceRoot}"
],
"clang-format.executable": "C:/Program Files/LLVM/bin/clang-format.exe",
"files.associations": {
"qjsonobject": "cpp",
"ostream": "cpp",
"qwebenginepage": "cpp",
"vector": "cpp",
"*.rh": "cpp",
"qwidget": "cpp",
"system_error": "cpp",
"xlocale": "cpp",
"qwebenginehistory": "cpp",
"iosfwd": "cpp",
"xstring": "cpp",
"xutility": "cpp"
},
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/GPATH": true,
"**/GRTAGS": true,
"**/GTAGS": true,
"**/*.user": true,
"**/Makefile*": true,
"**/debug": true,
"**/release": true,
"**/Debug": true,
"**/Release": true,
"**/*.exe": true,
"**/*.dll": true,
"**/*.stash": true,
"**/*.bat": true,
"**/*.cmd": false,
"**/*cache": true,
"**/*.sdf": true,
"**/*.suo": true,
"**/Win32": true,
"**/ipch": true,
"**/x64": true,
"**/GeneratedFiles": true,
"**/build": true
}
以上配置成功后自动提示、语法高亮、代码导航等功能可以正常工作。
修改默认的编译任务,即tasks.json,代码如下:
{
"version": "2.0.0",
"tasks": [{
"taskName": "demo1 Debug",
"type": "shell",
"command": "cmd",
"args": [
"/c",
"${workspaceRoot}/build.cmd",
"debug"
],
"group": {
"kind": "build",
"isDefault": true
}
}]
}
新建build.cmd,代码如下:
@echo off
title qmake and nmake build prompt
set VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
set QTDIR=C:\Qt\Qt5.9.1\5.9.1\msvc2015_64
set PATH=%VCINSTALLDIR%\bin;%QTDIR%\bin;C:\Program Files\7-Zip;%PATH%
call "%VCINSTALLDIR%\vcvarsall.bat" amd64
qmake demo1.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
nmake
cd debug
windeployqt demo1.exe
新建launch.json,代码如下:
{
"version": "0.2.0",
"configurations": [{
"name": "CDB",
"type": "cppvsdbg",
"request": "launch",
"program": "demo1.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/debug/",
"environment": [],
"externalConsole": true
}]
}
VSCode调试功能强于Qt,Qt UI设计功能又强于VSCode,两者互补,给我们工作带来不少方便。以上配置完成后就可以尝到C++与Qt联合工作的甜头了。
写两个局部变量看看:
int a=1;
int b=2;
int c=a+b;
qDebug()<"+"<"="<
至此,Visual Studio Code开发Qt应用程序实现自动提示、语法高亮、代码导航、编译和调试工作全部成功完成。