码迷,mamicode.com
首页 > 其他好文 > 详细

使用VSCode 编译调试QT程序

时间:2017-11-18 16:34:57      阅读:570      评论:0      收藏:0      [点我收藏+]

标签:environ   deploy   属性   nat   访问   div   soft   vscode   exist   

预备知识

  1. bat文件,或者其他的脚本
  2. qmake基本语法,qmake shadow build
  3. vscode 的task配置

前提

  1. 各个程序正确安装,即使用QtCreator可以正常编译运行
  2. 使用QtCreator生产.pro文件

编译运行

bat文件如下:

  1. debug版本

    @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
  2. relese版本

    @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
  3. namke 也可以换成QT默认的jom
  4. windeployqt 这个是QT自带的部署工具,可以搜素exe的所有依赖dll。调试的时候,若是不指定环境变量,需要将windeployqt打开,否则程序无法加载。当然,只要打开一次就够了,因为此时所有必要的的dll已经全部复制到程序目录下了。

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文件。
然后配置文件如下:

{
    // 使用 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程序

标签:environ   deploy   属性   nat   访问   div   soft   vscode   exist   

原文地址:http://www.cnblogs.com/WeyneChen/p/7857063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!