不兼容类型
此警告类别由 qmllint 拼写[incompatible-type]
。
无法赋值给不兼容类型的默认属性
发生了什么事?
你将一个对象赋值给了不兼容类型的默认属性。
为什么会这样?
QML Runtime 引擎将无法在运行时分配对象。
示例
import QtQuick Item { component MyType: QtObject { default property list<Item> myDefaultProperty } MyType { QtObject {} // note: QtObject does not inherit from Item } }
要修复此警告,请为属性绑定兼容类型,或者,如果您是默认属性的作者,请更改定义中的类型:
import QtQuick Item { component MyType: QtObject { default property list<Item> myDefaultProperty } MyType { Item {} } component AlternativeMyType: QtObject { default property list<QtObject> myDefaultProperty } AlternativeMyType { QtObject {} // is ok for AlternativeMyType } }
属性绑定时类型错误
发生了什么事?
你使用了无效的属性修改器类型。
为什么会这样?
QML Runtime 引擎无法在运行时使用该属性修饰符类型。
示例
import QtQuick Item { property int xxx Item on xxx { ... } }
要修复此警告,请删除on
或使用有效的属性修饰符类型:
import QtQuick Item { property int xxx Item { ... } // Alternative: use a valid property modifier type NumberAnimation on xxx { ... } }
从字符串构造已被弃用;请使用结构化值类型构造。
发生了什么?
您使用字符串构造了QML_STRUCTURED_VALUE 。
为什么这样做不好?
这已被弃用,而且容易造成错误。
示例
要修复此警告,请按照QML_STRUCTURED_VALUE 说明填充结构化值类型,而不是将字符串绑定到属性:
无返回类型注解的函数返回
发生了什么?
您从一个没有返回类型注解的函数返回了一个值。
为什么会这样?
您注解函数不返回任何东西,所以函数不应该返回任何东西。QML 工具将无法处理该方法,QML 引擎将在未来的 Qt Qml 版本中忽略返回值。
示例
import QtQuick Item { function f(x: int) { ... return x } }
要修复此警告,可根据新的返回类型调整函数签名或删除返回值:
import QtQuick Item { function f(x: int): int { ... return x } function alternativeF(x: int) { ... return } }
无法分配绑定/对象/字段
发生了什么?
您将对象、文字或表达式绑定到了不兼容类型的属性上。
为什么会这样?
QML Runtime 引擎无法在运行时分配对象、字面或表达式。
示例
要修复此警告,请绑定兼容类型的对象、值或表达式:
© 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.