vscode 配置Qt qmake项目

Qt6更新后,官方推荐使用Cmake管理项目。为了兼容以前的老项目,又不想用qtcreator,于是乎使用vscode 配置qmake管理qt项目。

主要是四个配置文件的设置

cpp_json

bash 复制代码
{
    "configurations": [
        {
            "name": "Qt5.4-MinGW32-Release",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/include/**",
                "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/**"
            ],
            "defines": [
                "UNICODE",
                "_UNICODE",
                "WIN32",
                "_WIN32",
                "QT_CORE_LIB",
                "QT_GUI_LIB",
                "QT_WIDGETS_LIB",
                "QT_SQL_LIB",
                "QT_NETWORK_LIB",
                "QT_XML_LIB",
                "QT_OPENGL_LIB",
                "MINGW",
                "NDEBUG",
                "RELEASE"
            ],
            "configurationProvider": "ms-vscode.cpptools",
            "intelliSenseMode": "windows-gcc-x86",
            "compilerPath": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/gcc.exe",
            "browse": {
                "path": [
                    "${workspaceFolder}/**",
                    "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/include/**",
                    "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/**"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "cStandard": "c11",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}

launch.json

bash 复制代码
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Qt Debug (MinGW32)",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/bin/debug/${workspaceRootFolderName}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [
        {
          "name": "PATH",
          "value": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
        }
      ],
      "MIMode": "gdb",
      "miDebuggerPath": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        },
        {
          "description": "Set Disassembly Flavor to Intel",
          "text": "-gdb-set disassembly-flavor intel",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "build debug",
      "internalConsoleOptions": "openOnSessionStart",
      "visualizerFile": "c:\\Users\\admin\\AppData\\Roaming\\Code\\User\\workspaceStorage\\3901a5fed96905db4fecc163ee7baa36\\tonka3000.qtvsctools\\qt.natvis.xml"
    },
    {
      "name": "Qt Release (MinGW32)",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/bin/release/${workspaceRootFolderName}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [
        {
          "name": "PATH",
          "value": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
        }
      ],
      "MIMode": "gdb",
      "miDebuggerPath": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "build release",
      "internalConsoleOptions": "openOnSessionStart",
      "visualizerFile": "c:\\Users\\admin\\AppData\\Roaming\\Code\\User\\workspaceStorage\\3901a5fed96905db4fecc163ee7baa36\\tonka3000.qtvsctools\\qt.natvis.xml"
    },
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "externalConsole": true,
      "cwd": "c:/DevelopWork/GsolarTest/MainBranch/GsolarTest",
      "program": "c:/DevelopWork/GsolarTest/MainBranch/GsolarTest/build/Release/outRelease",
      "MIMode": "gdb",
      "miDebuggerPath": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

settings.json

bash 复制代码
{
  "files.associations": {
    "*.h": "cpp",
    "*.c": "c",
    "*.cpp": "cpp",
    "*.ui": "xml",
    "*.pro": "ini"
  },
  "C_Cpp.errorSquiggles": "enabled",
  "C_Cpp.intelliSenseEngine": "default",
  "C_Cpp.intelliSenseEngineFallback": "enabled",
  "C_Cpp.formatting": "clangFormat",
  "editor.formatOnSave": true,
  "C_Cpp.default.compilerPath": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/gcc.exe",
  "C_Cpp.default.includePath": [
    "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/include/**"
  ],
  "C_Cpp.default.cppStandard": "c++11",
  "C_Cpp.default.cStandard": "c11",
  "terminal.integrated.env.windows": {
    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
  },
  "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
  "C_Cpp_Runner.cCompilerPath": "gcc",
  "C_Cpp_Runner.cppCompilerPath": "g++",
  "C_Cpp_Runner.debuggerPath": "gdb",
  "C_Cpp_Runner.cStandard": "",
  "C_Cpp_Runner.cppStandard": "",
  "C_Cpp_Runner.useMsvc": false,
  "C_Cpp_Runner.warnings": [
    "-Wall",
    "-Wextra",
    "-Wpedantic",
    "-Wshadow",
    "-Wformat=2",
    "-Wcast-align",
    "-Wconversion",
    "-Wsign-conversion",
    "-Wnull-dereference"
  ],
  "C_Cpp_Runner.msvcWarnings": [
    "/W4",
    "/permissive-",
    "/w14242",
    "/w14287",
    "/w14296",
    "/w14311",
    "/w14826",
    "/w44062",
    "/w44242",
    "/w14905",
    "/w14906",
    "/w14263",
    "/w44265",
    "/w14928"
  ],
  "C_Cpp_Runner.enableWarnings": true,
  "C_Cpp_Runner.warningsAsError": false,
  "C_Cpp_Runner.compilerArgs": [],
  "C_Cpp_Runner.linkerArgs": [],
  "C_Cpp_Runner.includePaths": [],
  "C_Cpp_Runner.includeSearch": [
    "*",
    "**/*"
  ],
  "C_Cpp_Runner.excludeSearch": [
    "**/build",
    "**/build/**",
    "**/.*",
    "**/.*/**",
    "**/.vscode",
    "**/.vscode/**"
  ],
  "C_Cpp_Runner.useAddressSanitizer": false,
  "C_Cpp_Runner.useUndefinedSanitizer": false,
  "C_Cpp_Runner.useLeakSanitizer": false,
  "C_Cpp_Runner.showCompilationTime": false,
  "C_Cpp_Runner.useLinkTimeOptimization": false,
  "C_Cpp_Runner.msvcSecureNoWarnings": false
}

tasks.json

bash 复制代码
{
    "version": "2.0.0",
    "tasks": [
        // {
        //     "label": "create directories",
        //     "type": "shell",
        //     "command": "if not exist \"${workspaceFolder}/build\" mkdir \"${workspaceFolder}/build\" && if not exist \"${workspaceFolder}/bin\" mkdir \"${workspaceFolder}/bin\" && if not exist \"${workspaceFolder}/bin/debug\" mkdir \"${workspaceFolder}/bin/debug\" && if not exist \"${workspaceFolder}/bin/release\" mkdir \"${workspaceFolder}/bin/release\"",
        //     "windows": {
        //         "command": "cmd /c if not exist \"${workspaceFolder}\\build\" mkdir \"${workspaceFolder}\\build\" && if not exist \"${workspaceFolder}\\bin\" mkdir \"${workspaceFolder}\\bin\" && if not exist \"${workspaceFolder}\\bin\\debug\" mkdir \"${workspaceFolder}\\bin\\debug\" && if not exist \"${workspaceFolder}\\bin\\release\" mkdir \"${workspaceFolder}\\bin\\release\""
        //     },
        //     "group": "build",
        //     "presentation": {
        //         "echo": true,
        //         "reveal": "silent",
        //         "focus": false,
        //         "panel": "new",
        //         "showReuseMessage": true,
        //         "clear": true
        //     }
        // },
        // Debug 版本相关任务
        {
            "label": "qmake configure debug",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin/qmake.exe",
            "args": [
                "${workspaceFolder}/${workspaceRootFolderName}.pro",
                "CONFIG+=debug",
                "CONFIG-=release",
                "-spec",
                "win32-g++",
                "-o",
                "${workspaceFolder}/build/debug"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "dependsOn": "create directories",
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "qmake make debug",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/mingw32-make.exe",
            "args": [
                "-f",
                "Makefile",
                "DESTDIR=${workspaceFolder}/bin/debug"
            ],
            "options": {
                "cwd": "${workspaceFolder}/build/debug",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "dependsOn": "qmake configure debug",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "build debug",
            "type": "shell",
            "command": "",
            "dependsOrder": "sequence",
            "dependsOn": [
                "create directories",
                "qmake configure debug",
                "qmake make debug"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": false,
                "reveal": "silent",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": false,
                "clear": true
            }
        },
        // Release 版本相关任务
        {
            "label": "qmake configure release",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin/qmake.exe",
            "args": [
                "${workspaceFolder}/${workspaceRootFolderName}.pro",
                "CONFIG+=release",
                "CONFIG-=debug",
                "-spec",
                "win32-g++",
                "-o",
                "${workspaceFolder}/build/release"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "dependsOn": "create directories",
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "qmake make release",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/mingw32-make.exe",
            "args": [
                "-f",
                "Makefile",
                "DESTDIR=${workspaceFolder}/bin/release"
            ],
            "options": {
                "cwd": "${workspaceFolder}/build/release",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "dependsOn": "qmake configure release",
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "build release",
            "type": "shell",
            "command": "",
            "dependsOrder": "sequence",
            "dependsOn": [
                "create directories",
                "qmake configure release",
                "qmake make release"
            ],
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": false,
                "reveal": "silent",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": false,
                "clear": true
            }
        },
        // 清理任务
        {
            "label": "clean debug",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/mingw32-make.exe",
            "args": [
                "clean"
            ],
            "options": {
                "cwd": "${workspaceFolder}/build/debug",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "clean release",
            "type": "shell",
            "command": "C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin/mingw32-make.exe",
            "args": [
                "clean"
            ],
            "options": {
                "cwd": "${workspaceFolder}/build/release",
                "env": {
                    "PATH": "C:/DevelopSoftware/Qt5.4/5.4/mingw491_32/bin;C:/DevelopSoftware/Qt5.4/Tools/mingw491_32/bin;${env:PATH}"
                }
            },
            "group": {
                "kind": "build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,
                "clear": true
            }
        }
    ]
}

使用方式:直接点击vscode的终端--运行任务,选择对应的任务即可。

相关推荐
kafei_*6 小时前
VScode 添加 UV虚拟环境方法
vscode·python·uv
小短腿的代码世界7 小时前
QtAV音视频播放实战深度解析:从零构建高性能跨平台播放器
qt·音视频
CSCN新手听安8 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
乐之者v11 小时前
AI编程 -- codex添加代码,在intellij Idea中没有显示,如何处理?
java·ide·intellij-idea
charlie11451419111 小时前
AwesomeQt:最小的Qt6系列迷你版本教程发布!
linux·c++·qt·c
CSCN新手听安12 小时前
【Qt】系统相关(一)内容简介,事件概念,事件的处理
开发语言·c++·qt
Eric.Lee202113 小时前
vscode格式化代码
ide·vscode·编辑器·c++格式化
比特 GOK13 小时前
Qt项目ui文件中新添加的控件在代码中不识别的问题解决
开发语言·qt·ui
会笑的小熊14 小时前
VScode项目推送到git仓库
ide·git·vscode
繁星蓝雨14 小时前
Qt多界面创建的优化问题(main函数或主界面中创建?)—————附带详细方法
c++·qt·架构·多界面管理