【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
相关推荐
小小码农Come on16 小时前
QT内存管理
开发语言·qt
有理想的打工人16 小时前
QT的安装
qt
一路向北North17 小时前
vscode 安装插件非常慢
ide·vscode·编辑器
SilentSlot18 小时前
【QT-QML】8. 输入元素
qt·qml
是店小二呀18 小时前
Visual Studio C++ 工程架构深度解析:从 .vcxproj 到 Qt MOC 的文件管理实录
c++·qt·visual studio
枫叶丹418 小时前
【Qt开发】Qt系统(十二)-> Qt视频
c语言·开发语言·c++·qt·音视频
民国二十三画生18 小时前
Trae.cn 编辑器四大功能(builder/chat/builder with MCP/SOLO coder)大白话区别
编辑器
浅碎时光80718 小时前
Qt (信号与槽 Widget控件 qrc文件)
开发语言·qt
Blue桃之夭夭19 小时前
【工具教程】Windows 下十六进制编辑器 HxD 安装与使用指南(附下载链接)
windows·编辑器
小乔的编程内容分享站19 小时前
C语言函数的声明和定义(文章包括当VScode中含多个.c文件且含.h文件如何同时编译
c语言·开发语言·vscode