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