• 修改运行配置文件./.vscode/launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "debug",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceRoot}/build/debug/VsCodeQMakeMinGw.exe",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                // 修改gdb路径
                // "miDebuggerPath": "D:/Programs/Qt/5.15.2/mingw81_64/bin/gdb.exe",
                "miDebuggerPath": "D:/Programs/Qt/Tools/mingw810_64/bin/gdb.exe",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "debug"
            }
        ]
    }
     class="hljs-button signin active add_def" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
  • 这时候编译运行应该能直接弹出Qt窗口了

    在这里插入图片描述

  • VsCode+QMake+Msvc

    VsCode+CMake+MinGw

    VsCode+CMake+Msvc

    QtCreator+QMake+MinGw->VsCode

    QtCreator+QMake+Msvc->VsCode

    QtCreator+CMake+MinGw->VsCode

    QtCreator+CMake+Msvc->VsCode

    脚本和配置的通用化

    VsCode+QMake

    @echo off
    title qmake and nmake build prompt
    
    set TARGET_NAME=VsCodeQMake
    set BUILD_NAME=debug
    set IS_MSVC=1
    if %IS_MSVC%==1 ( set QT_DIR=D:\Programs\Qt\5.15.2\msvc2015_64
    ) else ( set QT_DIR=D:\Programs\Qt\5.15.2\mingw81_64
    )
    set PRO_DIR=%cd%
    
    for %%A in ("%QT_DIR%") do (set "QT_KIT_NAME=%%~nxA")
    for %%A in ("%QT_DIR%\..") do (set "QT_VERSION=%%~nxA")
    set "QT_VERSION=%QT_VERSION:.=_%"
    
    echo %QT_KIT_NAME%| findstr /i "msvc">nul
    if errorlevel 1 ( set QT_KIT_STR=MinGW
    set IS_MSVC=0
    ) else ( set QT_KIT_STR=%QT_KIT_NAME:~0,-3%
    set IS_MSVC=1
    for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set QT_KIT_STR=%%QT_KIT_STR:%%i=%%i%%
    )
    
    echo %QT_KIT_NAME%| findstr /i "64" >nul
    if errorlevel 1 ( set BIT_STR=32bit) else ( set BIT_STR=64bit)
    set QT_KIT_STR=Desktop_Qt_%QT_VERSION%_%QT_KIT_STR%_%BIT_STR%
    set BUILD_DIR=%PRO_DIR%/../build-%TARGET_NAME%-%QT_KIT_STR%
    
    set FIRST_CHAR=%BUILD_NAME:~0,1%
    for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set FIRST_CHAR=%%FIRST_CHAR:%%i=%%i%%
    set BUILD_NAME_U=%FIRST_CHAR%%BUILD_NAME:~1%
    
    if not exist "%QT_DIR%" exit
    if not exist "%PRO_DIR%" exit
    if not exist "%BUILD_DIR%" (
        md "%BUILD_DIR%"
    )
    
    if %BUILD_NAME%=="debug"( set CONFIG_STR="CONFIG+=%BUILD_NAME%" "CONFIG+=console") else(set CONFIG_STR="CONFIG+=%BUILD_NAME%")
    
    cd "%BUILD_DIR%"
    if %IS_MSVC%==1 ( goto build_msvc) else ( goto build_mingw)
    
    :build_msvc
      call "D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
      %QT_DIR%\bin\qmake.exe %PRO_DIR%\%TARGET_NAME%.pro -spec win32-msvc %CONFIG_STR%
      set TARGET_NAME_ALL=%BUILD_DIR%\%BUILD_NAME%\%TARGET_NAME%.exe
      if exist "%TARGET_NAME_ALL%" del "%TARGET_NAME_ALL%"
      nmake %BUILD_NAME_U%
      goto end
    
    
    :build_mingw
      set MINGW_PATH=%QT_DIR%\..\..\Tools\%QT_KIT_NAME:~0,7%0%QT_KIT_NAME:~-3%
      set PATH=%MINGW_PATH%\bin;%QT_DIR%\bin;%PATH%
    
      %QT_DIR%\bin\qmake.exe %PRO_DIR%\%TARGET_NAME%.pro -spec win32-g++ %CONFIG_STR%
      set TARGET_NAME_ALL=%BUILD_DIR%\%BUILD_NAME%\%TARGET_NAME%.exe
      if exist "%TARGET_NAME_ALL%" del "%TARGET_NAME_ALL%"
      @REM D:\Programs\Qt\Tools\QtCreator\bin\jom.exe -j4
      %MINGW_PATH%\bin\mingw32-make -f Makefile.%BUILD_NAME_U%
      goto end
    
    :end
    if not exist %BUILD_DIR%\%BUILD_NAME%\Qt5Cored.dll (
      %QT_DIR%\bin\windeployqt.exe "%TARGET_NAME_ALL%"
    )
     class="hljs-button signin active add_def" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
    注:本文转载自blog.csdn.net的柠檬野生菌的文章"https://blog.csdn.net/weixin_49500446/article/details/143990626"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
    复制链接

    评论记录:

    未查询到任何数据!