重复 ID

此警告类别由 qmllint 拼写为[syntax.duplicate-ids]

发现一个重复的 ID

发生了什么事?

您在不同的id 上使用了相同的值。

为什么会这样?

QML 语言禁止重复 id:在同一个 QML 组件中,所有 id 都应该是唯一的。

示例

import QtQuick

Item {
    id: root
    Item {
        id: root
    }
}

要修复这个警告,重命名重复的 id,使其成为唯一的:

import QtQuick

Item {
    id: root
    Item {
        id: notRoot
    }
}

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