Auf dieser Seite

Groß-/Kleinschreibung des Enum-Schlüssels

Diese Warnkategorie wird von qmllint als „ [enum-key-case] “ bezeichnet.

Enum-Schlüssel beginnt mit einem Kleinbuchstaben

Was ist passiert?

Eine Enum enthält einen Schlüssel, der mit einem Kleinbuchstaben beginnt.

Warum ist das schlecht?

Dies kann bei der Suche zu Mehrdeutigkeiten führen. Enum-Schlüssel sollten mit einem Großbuchstaben beginnen, um sie von Eigenschaften von Singletons und angehängten Objekten zu unterscheiden. Die Nichtbeachtung dieser Konvention kann zu unerwarteten Ergebnissen führen.

Beispiel

// Properties.qml
import QtQuick

Item {
    enum Color { red, green, blue }
}
// Main.qml
import QtQuick

Item {
    // This lookup could be interpreted as a property lookup on a Singleton or attached object.
    property int i: Properties.green
}

Um diese Warnung zu beheben, benennen Sie den Schlüssel so um, dass er mit einem Großbuchstaben beginnt.

// Properties.qml
import QtQuick

Item {
    enum Color { Red, Green, Blue }
}
// Main.qml
import QtQuick

Item {
    // No ambiguity for the user or the QML engine, this is an enum lookup.
    property int i: Properties.Green
}

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