【QML】vscode安装QML格式化插件方法

1. 安装插件

拓展 => 搜索qml => 找到QML Format =>点击安装

2. 配置

  • 打开settings.json文件
    • ctl + shift + p,然后搜索settings
  • 修改settings.js内容
c 复制代码
{
    ...
    //添加以下内容

    // 根据自己电脑安装路径来填写qmlformat.exe的路径,注意转义符"\" => "\\"
    "qmlFormat.command": "D:\\Soft\\Qt6\\5.15.2\\mingw81_64\\bin\\qmlformat.exe",

    // 命令选项,这里官方写的是--normal,但是报错,改成-n就好了
    // qmlFormat的命令选项见附录
    "qmlFormat.extraArguments": ["-n"]
}

3. 使用

  • 鼠标右键选择格式化文档
  • 快捷键 shift + alt + F

附录

  • qmlFormat.exe 命令选项
c 复制代码
./qmlformat -h                                       
Usage: ./qmlformat [options] filenames
Formats QML files according to the QML Coding Conventions.

Options:
  -h, --help                  Displays help on commandline options.
  --help-all                  Displays help including Qt specific options.
  -v, --version               Displays version information.
  -V, --verbose               Verbose mode. Outputs more detailed information.
  -i, --inplace               Edit file in-place instead of outputting to
                              stdout.
  -f, --force                 Continue even if an error has occurred.
  -t, --tabs                  Use tabs instead of spaces.
  -w, --indent-width <width>  How many spaces are used when indenting.
  -n, --normalize             Reorders the attributes of the objects according
                              to the QML Coding Guidelines.
  -F, --files <file>          Format all files listed in file, in-place
  -l, --newline <newline>     Override the new line format to use (native macos
                              unix windows).

Arguments:
  filenames                   files to be processed by qmlformat
相关推荐
小墨宝1 小时前
vscode自带内网穿透
ide·vscode·编辑器
BatyTao2 小时前
QT Creator快速创建主项目-子项目
qt
赤水无泪4 小时前
Qt 全模块汇总列表
开发语言·qt
蚂蚁不吃土&5 小时前
Visual Studio 修改编码格式
vscode
GoKu~5 小时前
QT视图界面
qt
日月新著5 小时前
在VSCode中通过Copilot链接Figma直接生成完整产品
vscode·copilot·figma
量子炒饭大师5 小时前
【2026全新 Claude Code + VScode + CCswitch + 接入deepseek-v4-pro 套餐】从环境配置到实战演练:Claude Code彻底开箱指南!
ide·vscode·编辑器·deepseek·claude code·cc-switch
3Tony5 小时前
解决VScode报错:preLaunchTask“C/C++: gcc.exe 生成活动文件“已终止,退出代码为 -1.
c++·ide·vscode
散一世繁华,颠半世琉璃5 小时前
30分钟搭建专业排版环境!VSCode+TeX Live 2025 保姆级教程
vscode
Dvesiz5 小时前
【ClaudeCode平替(免费)】OpenCode 完整安装与 VSCode 使用指南
ide·vscode·编辑器·github·ai编程·claude·visual studio code