本页内容

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
    }
}

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