优先使用非变量属性
qmllint 将此警告类别拼写为“[prefer-non-var-properties] ”。
优先使用比 var 更具体的类型
发生了什么?
您在 QML 中定义了一个类型为 `var ` 的属性,而非更具体的类型,例如 `int ` 或 `string `。
这有什么问题吗?
这会影响代码的可读性,且 QML 工具无法应用特定类型的优化。
对于始终保持相同类型的属性,应避免使用 `var ` 作为属性类型。为避免误报,qmllint 仅对具有简单绑定的只读属性发出警告。在其他情况下,它可能无法区分必须为 `var` 类型的属性(因其需要容纳多种类型)与始终保持相同类型的属性。
示例
要修复此警告,请将 `var ` 替换为具体类型。
© 2026 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.