VSCode中使用Qt

系列文章目录


文章目录


一、安装插件

在 vscode 市场中安装如下插件:


二、设置

在全局 settings.json 文件中进行如下设置:

json 复制代码
{
    // 格式化
    "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, ColumnLimit: 180, AlignConsecutiveMacros: true, AlignConsecutiveAssignments: true, AlignConsecutiveDeclarations: true, SpaceBeforeFunctionParentheses: true }",
    "editor.fontSize": 16,
    "cmake.configureSettings": {
        // 指定 cmake 路径
        "CMAKE_PREFIX_PATH": "E:/Qt/6.8.3/msvc2022_64",
        // 指定 make 路径
        "CMAKE_MAKE_PROGRAM": "E:/Qt/Tools/Ninja/ninja.exe"
    },
    // 指定环境变量
    "cmake.environment": {
        "PATH": "E:/work/PCIeSwitch/code/api/swApi/build/RelWithDebInfo;E:/Qt/6.8.3/msvc2022_64/bin;$env:PATH"
    },
    // 指定安装目录
    "qt-core.qtInstallationRoot": "E:/Qt/",
    "qt-ui.customWidgetsDesignerExePath": "E:/Qt/6.8.3/msvc2022_64/bin/designer.exe"
}

可在当前工程的 settings.json 文件中进行如下设置:

json 复制代码
{
    "cmake.configureSettings": {
        // "CMAKE_MAKE_PROGRAM": "C:/Program Files/CMake/bin/ninja.exe"
        "CMAKE_MAKE_PROGRAM": "E:/Qt/Tools/Ninja/ninja.exe"
    },
    "cmake.environment": {
        // "PATH": "E:/Qt/Tools/mingw1310_64/bin;$env:PATH"
        // "PATH": "E:/Qt/Tools/llvm-mingw1706_64/bin;$env:PATH"
        "PATH": "E:/work/PCIeSwitch/code/api/swApi/build/RelWithDebInfo;E:/Qt/6.8.3/msvc2022_64/bin;d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/HostX64/x64;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VC/VCPackages;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer;d:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/bin/Roslyn;d:/Program Files/Microsoft Visual Studio/2022/Community/Team Tools/DiagnosticsHub/Collector;C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0//x64;C:/Program Files (x86)/Windows Kits/10/bin//x64;d:/Program Files/Microsoft Visual Studio/2022/Community//MSBuild/Current/Bin/amd64;C:/Windows/Microsoft.NET/Framework64/v4.0.30319;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/Tools/;C:/Program Files (x86)/Common Files/Oracle/Java/java8path;C:/Program Files (x86)/Common Files/Oracle/Java/javapath;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/WINDOWS/System32/WindowsPowerShell/v1.0/;C:/WINDOWS/System32/OpenSSH/;C:/Program Files/dotnet/;C:/Program Files/SourceGear/Common/DiffMerge/;C:/Program Files/CMake/bin;C:/Program Files/usbipd-win/;E:/nodeDir/node_global;C:/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/;C:/ProgramData/chocolatey/bin;D:/Program Files/Git/cmd;D:/Program Files/nodejs/;D:/Program Files/TortoiseGit/bin;C:/Program Files (x86)/Windows Kits/10/Debuggers/x64;C:/Users/LucasLiu/AppData/Local/Microsoft/WindowsApps;d:/Microsoft VS Code/bin;;C:/Users/LucasLiu/AppData/Local/Programs/Ollama;C:/Users/LucasLiu/AppData/Roaming/npm;C:/Users/LucasLiu/AppData/Roaming/Programs/Zero Install;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja;d:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VC/Linux/bin/ConnectionManagerExe;d:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg;$env:PATH",
        "INCLUDE": "d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include;d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/ATLMFC/include;d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include;C:/Program Files (x86)/Windows Kits/10/include/10.0.26100.0/ucrt;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//um;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//shared;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//winrt;C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//cppwinrt;$env:INCLUDE",
        "LIB": "d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/ATLMFC/lib/x64;d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/lib/x64;C:/Program Files (x86)/Windows Kits/10/lib/10.0.26100.0/ucrt/x64;C:/Program Files (x86)/Windows Kits/10//lib/10.0.26100.0//um/x64;$env:LIB",
    }
}

.vscode\c_cpp_properties.json 中设置头文件

json 复制代码
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "E:/Qt/6.8.3/msvc2022_64/include/**",
                "E:/Qt/6.8.3/msvc2022_64/qml/**",
                "D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/**",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/**",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/ucrt/**",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/**",
                "E:/Qt/Tools/QtCreator/bin/clang/lib/clang/20/include/**",
                "E:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/bits/**",
                "E:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/**",
                "E:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/**",
                "E:/work/PCIeSwitch/code/api/swApi/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ]
            // "compilerPath": "E:/Qt/Tools/mingw1310_64/bin/g++"
        }
    ],
    "version": 4
}
相关推荐
ahauedu1 分钟前
30分钟入门实战速成Cursor IDE(2)
ide·ai编程·cursor
想文艺一点的程序员2 小时前
ESP32S3:开发环境搭建、VSCODE 单步调试、Systemview 分析任务运行情况
ide·vscode·编辑器
johnny2333 小时前
Vibe Coding、AI IDE/插件
ide·人工智能
何为xl16 小时前
【VSCode】使用VSCode打开md文件以及转化为PDF
ide·vscode·pdf
每天敲200行代码20 小时前
QT 概述(背景介绍、搭建开发环境、Qt Creator、程序、项目文件解析、编程注意事项)
c++·qt
卿·静1 天前
Node.js终极文本转图指南
前端·javascript·vscode·node.js
北极之熊熊1 天前
【AI自动化】VSCode+Playwright+codegen+nodejs自动化脚本生成
运维·vscode·自动化·ai ui自动化测试
salestina1 天前
vsCode如何自定义编辑器背景色
ide·vscode·编辑器
sun0077001 天前
vscode 调试 指定 python文件 运行路径
ide·vscode·编辑器
xiaobobo33301 天前
关于vscode的右键常用操作以及自定义快捷键
ide·vscode·编辑器