vscode-QT环境配置

vscode-QT环境配置

参考链接:https://www.cnblogs.com/RioTian/p/18281114

一、 背景

  1. 已经安装了QT软件,电脑里有了QT Creater 12.0。
  2. 使用QT生成并运行了一个project
  3. 在这个project的基础上,直接配置vscode的环境

二、环境配置

  1. 确认QT工程成功运行

  2. 确认QT的运行配置

    • 这个看起来是构建的配置

    • 运行路径看起来没什么特别的,就是执行exe文件

  3. 用构建命令运行一下

    • 点击详情,确认一下工具的地址

      如果需要的话,后续这个工具应该配置到环境变量里面。方便一点

    • qmake运行pro文件

      • qmake.exe .../LogTool.pro

        可能是一些需要的环境配置吧,不太懂makefile

      • 执行的时候把所有参数都去了,等有问题再回来研究参数吧

      • 后半段有个make的运行,再试试:make qmake_all

      • 用了原命令也报相同的问题。暂时忽略,直接进入第二步,正好也是make

    • D:\Software\Qt6\Tools\mingw1120_64\bin\mingw32-make.exe -j4 in ./debug

      • 模仿原命令写的,报错了

      • in应该是个伪代码,重新尝试一下先进入命令,然后运行make

      • 确认结果

        debug目录多了一些东西

        看起来问题不大,但是无法运行。。。。

      • 应用无法在电脑上运行

        QT环境配置的时候就踩过这个坑

        之前的结论是,release的命令好使

        • 使用release的命令 + mingw32-make编译到debug目录

          重新生成了一下,debug目录还是无法运行

        • 用release的命令 + make试一下


          可以确认应用无法运行的问题解决了

        • 回顾一下QT的编辑log

          按照这个设置输命令,在debug目录生成了exe,直接执行也会提示版本不对,无法执行。换成之前配置过的mingw包里面的make就行了

          D:\Software\Qt6\6.6.3\mingw_64\bin\qmake.exe ../LogTool.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"

          make -j7 release

          以下是版本参考

        • 配置环境变量,解决库的问题

          需要将Qt的mingw放到原有的mingw上,否则会提示引用的库找不到入口点

          https://blog.csdn.net/weixin_44965579/article/details/141187782

          但是这样设置的话,运行exe其实还是依赖环境变量。不是最优解法......

        • 添加依赖库

          https://blog.csdn.net/Zander0/article/details/121741365

          D:\BasicSetting\Qt_mingw64\bin\windeployqt.exe LogTool.exe

  4. 确认编译步骤

    • D:\Software\Qt6\6.6.3\mingw_64\bin\qmake.exe ../LogTool.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
    • make -j7
    • windeployqt LogTool.exe
  5. 安装Vscode的相关插件

    • QT UI

      • 用以读取.ui文件

      • ctrl+shift+p

  6. 配置ui文件

    • 配置launch.json

      上面装组件的方式,没有成功运行Designer,于是放弃

      launch的方式配置。每次打开ui文件,执行用Designer.exe打开ui文件的命令,达到类似的效果

      json 复制代码
      {
          "version": "0.2.0",
          "configurations": [        
              {
                  "name": "ui Set",
                  "type": "cppdbg",
                  "request": "launch",
                  "program": "D:\\BasicSetting\\Qt_mingw64\\bin\\designer.exe",
                  "cwd": "${workspaceFolder}",
                  "stopAtEntry": false,
                  "externalConsole": false,
                  "args": [
                      "${file}"
                  ],
                  "setupCommands": [
                      {
                          "description": "Enable pretty-printing for gdb",
                          "text": "-enable-pretty-printing",
                          "ignoreFailures": true
                      }
                  ]
              }
          ]
      }
  7. Qt编译环境配置

    • 配置launch.json

      json 复制代码
      {
          "version": "0.2.0",
          "configurations": [
              {
                  "name": "QtBuild",
                  "type": "cppdbg",
                  "request": "launch",
                  "program": "${fileDirname}/Out/release/${relativeFileDirname}.exe",
                  "args": [],
                  "stopAtEntry": false,
                  "cwd": "${fileDirname}",
                  "environment": [],
                  "externalConsole": false,
                  "MIMode": "gdb",
                  "preLaunchTask": "QtBuild",
                  "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
                      }
                  ]
              },
              {
                  "name": "ui Set",
                  "type": "cppdbg",
                  "request": "launch",
                  "program": "D:\\BasicSetting\\Qt_mingw64\\bin\\designer.exe",
                  "cwd": "${workspaceFolder}",
                  "stopAtEntry": false,
                  "externalConsole": false,
                  "args": [
                      "${file}"
                  ],
                  "setupCommands": [
                      {
                          "description": "Enable pretty-printing for gdb",
                          "text": "-enable-pretty-printing",
                          "ignoreFailures": true
                      }
                  ]
              }
          ]
      }
    • 配置tasks.json

      json 复制代码
      {
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "createOut",
                  "type": "shell",
                  "group": {
                      "kind":"build",
                      "isDefault": true
                  },
                  "command": "PowerShell",
                  "args": [
                      "if (-not (Test-Path \"Out\")) { New-Item -ItemType Directory -Path \"Out\" }" //Power shell的命令,找out目录,如果没有就创建文件
                  ],
                  "options": {
                      "cwd": "${fileDirname}",
                  }
              },
              {
                  "label": "ProBuild",  //在out目录下,编译pro文件
                  "type": "shell",
                  "command": "D:\\BasicSetting\\Qt_mingw64\\bin\\qmake.exe",
                  // "command": "ls",
                  "problemMatcher": [],
                  "args": [
                      "${fileDirname}\\${relativeFileDirname}.pro"
                  ],
                  "options": {
                      "cwd": "${fileDirname}\\Out\\",
                      "shell": {
                          "executable": "PowerShell"
                      }
                  },
                  "dependsOn":[
                  ],
              },
              {
                  "label": "makeFile", //在out目录下,将makefile生成为exe
                  "command": "D:\\BasicSetting\\mingw64\\bin\\make.exe",
                  // "command": "ls",
                  "args": [
                      "-j8",
                      "release"
                  ],
                  "options": {
                      "cwd": "${fileDirname}\\Out\\"
                  },
                  "dependsOn":[
                  ],
              },
              {
                  "label": "deployDll",  //将exe需要的部署到此目录
                  "command": "D:\\BasicSetting\\Qt_mingw64\\bin\\windeployqt.exe",
                  // "command": "ls",
                  "args": [
                      "${relativeFileDirname}.exe"
                  ],
                  "options": {
                      "cwd": "${fileDirname}\\Out\\release",
                      "shell": {
                          "executable": "PowerShell"
                      }
                  },
                  "dependsOn":[
                  ],
              },
      
              {
                  "label": "QtBuild",   //launch的QtBuild的前置程序
                  "dependsOrder": "sequence", //依赖task的运行顺序是顺序执行的(另外一个选项是并行)
                  "dependsOn":[
                      "createOut", //创建out目录
                      "ProBuild",  //编译Pro文件
                      "makeFile",  //make命令
                      "deployDll"  //部署依赖的库
                  ],
              }
          ]
      }
相关推荐
黄河里的小鲤鱼26 分钟前
使用Pycharm一键将.ui文件生成.py文件配置教程
ide·ui·pycharm
臣妾写不来啊2 小时前
2025/03/19 Cursor使用方法(Java方向,适合Java后端把家从idea搬家到cursor)
java·ide·intellij-idea
ACE叫牌2 小时前
C++Qt开发流程图效果,包括保存、加载功能
c++·qt·流程图·visual studio code
心灵宝贝4 小时前
IntelliJ IDEA 2023.3.1安装指南从下载到配置的完整教程(附资源下载)
java·ide·intellij-idea
碧海蓝天20226 小时前
替代Qt中信号与槽的完整例子。
开发语言·qt
花花鱼9 小时前
vscode vue3 jsconfig 与 tsconfig的区别
ide·vscode·编辑器
Warren9812 小时前
十分钟学会Git
java·ide·笔记·git·gitee
灏瀚星空15 小时前
在 Visual Studio Code 中高效使用 Pylance:配置、技巧与插件对比
ide·经验分享·vscode·python·编辑器·学习方法
北漂老男孩16 小时前
IntelliJ IDEA 调试技巧指南
java·ide·intellij-idea
正经教主17 小时前
【菜鸟飞】在vsCode中安装python的ollama包出错的问题
开发语言·人工智能·vscode·python·ai·编辑器