预备知识
- bat文件,或者其余的脚本语法。
- qmake基本语法,qmake shadow build是啥。
- vscode 的task,lanch的配置。
前提
- 各个程序正确安装,即便用QtCreator能够正常编译调试。
- 使用QtCreator生成工程。
这里演示的是使用MSVC + CDB,所以VS和windows调试工具要装好。固然也是可使用GCC + GDB的。html
脚本
我这里使用bat文件。c++
bat文件以下:git
debug版本--build_debug.cmd
@echo off title qmake and nmake build prompt set VCINSTALLDIR=D:\Microsoft Visual Studio 14.0\VC set QTDIR=D:\Qt\Qt5.9.1\5.9.1\msvc2015_64 set PATH=%VCINSTALLDIR%\bin;%QTDIR%\bin;D:\7-Zip;%PATH% ::shadow build cd .. set file = tips-build-debug-msvc2015_64 if NOT exist %file% ( mkdir tips-build-debug-msvc2015_64 cd tips-build-debug-msvc2015_64 call "%VCINSTALLDIR%\vcvarsall.bat" amd64 qmake ../tips/tips.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug" nmake cd debug ::windeployqt tips.exe ::tips.exe
注意点:github
- namke 也能够换成QT默认的jom。
- windeployqt 这个是QT自带的部署工具,能够搜素exe的全部依赖dll。调试的时候,如果不指定环境变量,须要将windeployqt打开,不然程序没法加载dll。固然,只要打开一次就够了,由于此时全部必要的的dll已经所有复制到程序目录下了。
release版本 -- release_debug.cmd
@echo off title qmake and nmake build prompt set VCINSTALLDIR=D:\Microsoft Visual Studio 14.0\VC set QTDIR=D:\Qt\Qt5.9.1\5.9.1\msvc2015_64 set PATH=%VCINSTALLDIR%\bin;%QTDIR%\bin;D:\7-Zip;%PATH% ::shadow build cd .. set file = tips-build-release-msvc2015_64 if NOT exist %file% ( mkdir tips-build-release-msvc2015_64 cd tips-build-release-msvc2015_64 call "%VCINSTALLDIR%\vcvarsall.bat" amd64 qmake ../tips/tips.pro -spec win32-msvc "CONFIG+=release" "CONFIG+=qml_release" nmake cd release ::windeployqt tips.exe tips.exe
Task
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build_debug", "type": "shell", "command": "cmd", "args": [ "/c", "build_debug.cmd" ], "group": "build", "presentation": { // Reveal the output only if unrecognized errors occur. "reveal": "silent" }, // Use the standard MS compiler pattern to detect errors, warnings and infos "problemMatcher": "$msCompile" }, { "label": "build_release", "type": "shell", "command": "cmd", "args": [ "/c", "build_release.cmd" ], "group": "build", "presentation": { // Reveal the output only if unrecognized errors occur. "reveal": "silent" }, // Use the standard MS compiler pattern to detect errors, warnings and infos "problemMatcher": "$msCompile" } ] }
调试
先读这里https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md,介绍了怎么配置c++的lanch文件。
而后配置文件以下:shell
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "CDB", "type": "cppvsdbg", "request": "launch", "program": "tips.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}/../tips-build-debug-msvc2015_64/debug/", "environment": [], //"symbolSearchPath": "C:\\Symbols", "externalConsole": true, "logging": { "moduleLoad": false, "trace": true }, "visualizerFile": "my.natvis" } ] }
使用上面的配置须要先build再run,若是加上一个参数:json
"preLaunchTask":"build_debug"
便可实现每次按F5,自动开始从新编译而且开始调试程序。windows
至此,VSCode已经能够编译调试Qt的程序了。markdown