【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
相关推荐
我是小灰灰吖2 小时前
Ubuntu 22.04 切换为 X11 会话以解决 QT 桌面程序兼容性问题
linux·qt·ubuntu
≮傷£≯√2 小时前
QT配置FFmpeg
开发语言·qt·ffmpeg
weixin_469273813 小时前
.md文件是什么?.md如何打开?
前端·编辑器
≮傷£≯√4 小时前
配置 opencv Qt项目
人工智能·qt·opencv
W_chuanqi4 小时前
VSCode + Claude Code + DeepSeek:打造 AI 编程神器
ide·vscode·编辑器·ai编程
csdn_aspnet4 小时前
在 Visual Studio Code 中安装使用 Github Copilot
ide·vscode·github·copilot
qq_401700415 小时前
Qt Modbus协议0x00
开发语言·qt
Zenova EdgeOS5 小时前
C++ 工业边缘 Qt 桌面应用实战:从 QWidget 到模型视图、网络与多线程
网络·c++·qt
凌云拓界17 小时前
NodeVerdict | .ndv 二进制格式:为 WASM 解码器设计的紧凑布局
安全·架构·开源·node.js·编辑器·软件工程·wasm
沫璃染墨19 小时前
《Qt从零入门系列(一):Qt框架初识——从发展历史到跨平台开发》
c++·qt·系统架构·gui