本页内容

枚举条目与枚举项匹配

qmllint 将此警告类别拼写为“[enum-entry-matches-enum] ”。

枚举条目的名称应与枚举本身不同

发生了什么?

某个枚举与其其中一个条目名称相同。

这有什么问题?

这可能会导致查找结果出现歧义,请参见下例。

示例

// Main.qml
import QtQuick

Item {
    enum E { A, B, C, D, E }
    property var v: Main.E // Does this refer to the enum or to its entry?
}

要解决此警告,请通过重命名枚举或枚举项来消除名称冲突:

// Main.qml
import QtQuick

Item {
    enum Enum { A, B, C, D, E }
    property var v: Main.E // v contains Enum.E. No more ambiguity is possible
}

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