qmlformat
qmlformat
qmlformat是一种按照QML 编码约定自动格式化 QML 文件的工具。更多
选项
有以下选项
选项 | 默认值 | 说明 |
---|---|---|
-h, -help | 显示命令行选项的帮助。 | |
-help-all | 显示包括通用 Qt 选项在内的帮助。 | |
-v, -version | 显示版本信息。 | |
-V, -verbose | 详细模式。输出更详细的信息。 | |
-write-defaults | 将默认设置写入 .qmlformat.ini 并退出(警告:这将覆盖任何现有设置和注释!)。 | |
-忽略设置 | 忽略所有设置文件,只考虑命令行选项 | |
-i、-就地 | 就地编辑文件,而不是输出到 stdout。 | |
-f, -force | 即使出现错误也继续编辑。 | |
-t, -tabs | 使用制表符代替空格。 | |
-w, -indent-width <width | 4 | 缩进时使用多少个空格。 |
-W,-column-width <width | -1 | 如果行宽超过指定宽度,则将行分成多行。使用 -1 可禁用换行。(默认)。 |
-n,-规范化 | 根据 QML 编码指南重新排列对象的属性。 | |
-F, -files <file> 文件 | 就地格式化文件中列出的所有文件 | |
-l, -newline <新行 | 覆盖要使用的新行格式(本地 macos unix windows)。 | |
-objects-spacing | 确保对象之间有空格(仅适用于 normalize 选项)。 | |
-函数间距 | 确保函数之间的空格(仅适用于 normalize 选项)。 |
参数
参数: |
---|
文件名 |
详细信息
qmlformat非常灵活,可以根据需要进行配置。
输出
qmlformat 会将格式化后的文件写入 stdout。如果希望就地更新文件,请指定-i
标志。
将属性、函数和信号组合在一起
使用-n
或--normalize
标志,qmlformat会将所有属性、函数和信号分组,而不是保留你指定的顺序。
设置文件
你可以通过在项目源代码或项目源代码文件夹的父目录中包含一个设置文件.qmlformat.ini
来配置qmlformat。通过--write-defaults
标志可以获得默认设置文件。这会在当前工作目录下生成.qmlformat.ini
文件。
警告: --write-defaults
会覆盖任何现有设置和注释!
格式化文件列表
虽然你可以把要格式化的文件列表作为参数传递,但 qmlformat 提供了-F
选项,用于格式化存储在文件中的一组文件。在这种情况下,格式化将就地进行。
// FileList.txt main.qml mycomponent.qml
那么,使用它就像
qmlformat -F FileList.txt
注意: 如果文件中包含无效条目,例如,文件路径不存在或文件路径有效但内容是无效的 qml 文档,那么qmlformat
将对该特定条目出错。它仍会格式化有效的文件条目。
警告 如果提供 -F 选项,qmlformat 将忽略位置参数。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.