Enum-Eintrag entspricht enum

Diese Warnkategorie wird von qmllint [enum-entry-matches-enum] geschrieben.

Enum-Eintrag sollte anders benannt werden als die Enum selbst

Was ist passiert?

Ein enum hat den gleichen Namen wie einer seiner Einträge.

Warum ist das schlecht?

Es kann mehrdeutig sein, was ein Lookup auflöst, siehe Beispiel unten.

Beispiel

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

Um diese Warnung zu beheben, lösen Sie den Namenskonflikt auf, indem Sie entweder die enum oder den enum-Eintrag umbenennen:

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