欢迎来到代码驿站!

C代码

当前位置:首页 > 软件编程 > C代码

vscode+qt5+cmake编译调试过程解析

时间:2022-09-28 09:38:54|栏目:C代码|点击:

环境

  • os: win11
  • cmake: 3.23
  • qt: qt5.14
  • 其他vscode c++辅助开发插件, 我的插件列表

编译vscode + cmake + qt5.14

文件列表

cmakelists.txt完整内容

cmake_minimum_required(VERSION 3.18)

project(cmake_demo01 LANGUAGES CXX)
set(CMAKE_PREFIX_PATH "C:/major/development/tools/qt/5.14/install/5.14.2/msvc2015_64")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Widgets Gui Core LinguistTools REQUIRED)
# set(TS_FILES cmake_demo01_zh_CN.ts)
file(GLOB_RECURSE src_file ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE inc_file ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
# file(GLOB_RECURSE ui_file ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.ui)
# qt5_wrap_ui(wrap_ui_file ${ui_file})
# SOURCE_GROUP("ui" FILES ${ui_file} ${wrap_ui_file})
  add_executable(${PROJECT_NAME}
    ${src_file}
    ${inc_file}
    # ${wrap_ui_file}
    # ${TS_FILES}
  )
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include  ${CMAKE_CURRENT_SOURCE_DIR}/ui)
# target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(cmake_demo01 PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui)
# qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

编译

  • 打开 command platette(ctrl + ,) 依次执行: cmake:select a kit 、cmake:select variant、 cmake:build
  • 编译结果:

调试

build.cmd

文件内容需要替换为本机的Qt和msvc编译器路径

title test build command
set VCINSTALLDIR=C:\major\development\tools\vs_2015\install\VC
set QTDIR=C:\major\development\tools\qt\5.14\install\5.14.2\msvc2015_64
set PATH=%PATH%;%QTDIR%\bin
call "%VCINSTALLDIR%\vcvarsall.bat" amd64
cmake --build ./build --config Debug --target cmake_demo01 -j 14 --

task.json

{
    "version": "2.0.0",
    "tasks": [{
        "taskName": "qt5",
        "type": "shell",
        "command": "cmd",
        "args": [
            "/c",
            "${workspaceRoot}/build.cmd",
            "debug"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }]
}

lauch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "cl.exe ",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/build/debug/${workspaceFolderBasename}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "console": "externalTerminal",
            "preLaunchTask": "qt5"
        }
    ]
}

F5调试

上一篇:C语言深入探究动态规划之线性DP

栏    目:C代码

下一篇:详解C++编程中的私有继承和公有继承

本文标题:vscode+qt5+cmake编译调试过程解析

本文地址:http://www.codeinn.net/misctech/214869.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有