本页内容

ID 与 shadows 成员

qmllint 将此警告类别拼写为[id-shadows-member] 。

ID 遮蔽了属性、方法或信号

发生了什么?

某个标识符可能在同一上下文中遮蔽了某个属性、方法或信号。

这有什么问题?

您将无法再通过其未限定名称访问该属性、方法或信号。原先这样操作的代码将转而默默访问该 id,这可能会导致难以发现的错误。

示例

import QtQuick

Item {
    Item { id: helloWorld }
    property int helloWorld: 42
    Component.onCompleted: console.log(helloWorld) // not 42
}

要解决此警告,请重命名该标识符或被遮蔽的成员。

import QtQuick

Item {
    Item { id: helloWorldId }
    property int helloWorld: 42
    Component.onCompleted: console.log(helloWorld) // now 42
}

© 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.