【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
相关推荐
Ven%1 小时前
VsCode如何使用默认程序打开word Excel pdf等文件
ide·vscode·pdf·编辑器
Silence4Allen1 小时前
VSCode 设置源代码根目录
ide·vscode·python·编辑器·pythonpath
清醒的兰3 小时前
Qt 调试信息重定向到本地文件
开发语言·qt
AI+程序员在路上3 小时前
QT跨平台软件开发要点
开发语言·qt
mosepplin4 小时前
VSCODE 报错Fatal error: can‘t create CMakeFiles/hello_world.elf.dir/C_/Users/...
ide·vscode·编辑器
林枫依依4 小时前
Unity Webgl在编辑器中报错:Cannot connect to destination host
unity·编辑器·webgl
道剑剑非道5 小时前
QT开发技术【QT实现桌面右下角消息】
开发语言·数据库·qt
青松@FasterAI5 小时前
【动手学大模型开发】VSCode 连接远程服务器
服务器·ide·vscode
此刻我在家里喂猪呢6 小时前
qt之开发大恒usb3.0相机一
qt·相机开发·大恒usb3.0相机·工业相机开发
xMathematics11 小时前
计算机图形学实践:结合Qt和OpenGL实现绘制彩色三角形
开发语言·c++·qt·计算机图形学·cmake·opengl