缺少属性
此警告类别由 qmllint 拼写[missing-property] 。
无法为不存在的默认属性赋值
发生了什么?
您将一个对象赋值给了一个不存在的默认属性。
为什么会这样?
QML Runtime 引擎不能在运行时分配这个对象。
示例
要修复此警告,请指定您要绑定的属性,或者,如果您是该类型的作者,请将一个属性标记为默认:
import QtQuick Item { component MyType: QtObject { property Item myItem; } MyType { myItem: Item {} } component AlternativeMyType: QtObject { default property Item myItem; } AlternativeMyType { Item {} // bound to myItem via default property } }
属性不存在
发生了什么?
你将一个表达式赋值给了一个不存在的属性。
为什么会这样?
QML Runtime 引擎不能在运行时分配这个表达式。
示例
要修复此警告,请删除绑定或更正可能的错字:
未在类型上找到成员
发生了什么?
你在字段成员表达式中访问了一个 QML 工具找不到的成员。字段成员表达式是someId.someProperty 形式的表达式。
该成员可能根本不存在,例如您打错了字。或者它可能在运行时存在(因为它存在于始终存在的特定子类型上),但在静态声明的类型上不存在。
这为什么不好呢?
QML 工具找不到这个成员,这意味着去定义(go-to-definition)和自动完成(autocomplete)等功能无法工作。在运行时,如果该成员真的不存在,可能会出现错误或得到不正确的结果。如果该成员在运行时确实存在,则不会出错,但在这种情况下,由于错过了优化,仍会产生性能代价。
示例
属性实际上不存在
要修复此警告,请删除绑定或更正可能的错字:
属性存在,但类型不够精确
import QtQuick import QtQuick.Controls.Basic Item { component Message : Item { required property string sender required property string text } ListView { id: messageView delegate: Message {} } Button { text: "Reply to %1".arg(messageView.currentItem.sender) // not ok } }
要修复此警告,可将读取的对象转换为更精确的类型:
import QtQuick import QtQuick.Controls.Basic Item { component Message : Item { required property string sender required property string text } ListView { id: messageView delegate: Message {} } Button { text: "Reply to %1".arg((messageView.currentItem as Message).sender) // now ok } }
在示例中,messageView 的currentItem 属性的声明类型是Item ,而 没有sender 属性:sender 只定义在Message 中。但在这里,我们知道currentItem 总是包含Message ,因此我们可以使用类型断言将currentItem 转换为Message 。
© 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.