未解决的别名
此警告类别由 qmllint 拼写为[unresolved-alias]
。
未解决的别名
发生了什么事?
属性别名应包含对另一个属性的引用,另请参阅QML Object Attributes - Property Aliases(QML 对象属性 - 属性别名)。在本例中,它包含了对一个未找到的属性的引用。
为什么会这样?
运行时将不会创建具有未解决别名的组件实例:它们将是空的。
示例
import QtQuick Item { id: someId property int helloWorld property alias helloWorldAlias: helloWorld // not ok: aliases have to refer by id property alias helloWorldAlias2: someId.helloWorlddd // not ok: no helloWorlddd in someId property alias helloWorldAlias3: someIddd.helloWorld // not ok: someIddd does not exist }
要修复此警告,请确保别名属性的 id 和属性确实存在:
import QtQuick Item { id: someId property int helloWorld property alias helloWorldAlias: someId.helloWorld // ok: alias refers by id property alias helloWorldAlias2: someId.helloWorld // ok: helloWorld does exist in someId property alias helloWorldAlias3: someId.helloWorld // ok: someId does exist }
© 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.