枚举条目与枚举匹配

该警告类别由 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
}

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