vscode怎么写qt项目_使用VSCode 编译调试QT程序
預備知識
bat文件,或者其他的腳本語法。
qmake基本語法,qmake shadow build是啥。
vscode 的task,lanch的配置。
前提
各個程序正確安裝,即使用QtCreator可以正常編譯調試。
使用QtCreator生成工程。
這里演示的是使用MSVC + CDB,因此VS和windows調試工具要裝好。當然也是可以使用GCC + GDB的。
腳本
我這里使用bat文件。
bat文件如下:
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
注意點:
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"
}
]
}
調試
{
// 使用 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,如果加上一個參數:
"preLaunchTask":"build_debug"
即可實現每次按F5,自動開始重新編譯并且開始調試程序。
至此,VSCode已經可以編譯調試Qt的程序了。
總結
以上是生活随笔為你收集整理的vscode怎么写qt项目_使用VSCode 编译调试QT程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电动车在留几格电时充电合适?
- 下一篇: php定时发送生日模块消息_Rocket