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的终端--运行任务,选择对应的任务即可。

相关推荐
sycmancia2 小时前
Qt——应用程序中的主窗口
开发语言·qt
blog.pytool.com2 小时前
Ubuntu + VSCODE +aarch64 +qt +qmake +clangd
linux·qt·ubuntu
ฅ ฅBonnie2 小时前
使用 VSCODE 连接远程服务器上的容器
服务器·ide·vscode
守护安静星空2 小时前
esp32开发笔记-wifi网络
网络·笔记·vscode·单片机·tcp/ip
Predestination王瀞潞3 小时前
彻底解决IDEA Console控制台乱码(Python可供参考第一部分)
java·ide·intellij-idea
薛定猫AI3 小时前
【技术干货】Claude Code 桌面版重大更新:AI 辅助编程进入 IDE 原生时代
ide·人工智能
秋月的私语3 小时前
遥感影像拼接线优化工具:基于Qt+GDAL+OpenCV的从二到三实践
开发语言·qt·opencv
ol木子李lo3 小时前
Qt6 替代废弃 QMediaPlaylist 的解决方案
c语言·c++·vscode·qt·个人开发·visual studio·qt6.3
史迪仔01123 小时前
[QML] Popup 与 Dialog
开发语言·前端·javascript·c++·qt