Enum außerhalb des Wurzelelements deklariert

Diese Warnkategorie wird von qmllint mit [non-root-enum] geschrieben.

Enum außerhalb des Root-Elements deklariert

Was ist passiert?

Eine Enum wurde außerhalb des Root-Elements der Komponente deklariert.

Warum ist das schlecht?

Es wird nicht zugänglich sein. Auf Enums wird als <Komponentenname>.<optionaler Enum-Name>.<Enum-Eintrag> zugegriffen. Befindet sich die Aufzählung nicht in der Wurzel der Komponente, funktioniert diese Suche nicht.

Beispiel

// Main.qml
import QtQuick

Item {
    Item {
        id: item
        enum Color { Red, Green, Blue }
    }
}

Um diese Warnung zu beheben, verschieben Sie die Aufzählung in das Stammverzeichnis der Komponente:

// Main.qml
import QtQuick

Item {
    enum Color { Red, Green, Blue } // Accessible in Main.qml but also from other files
    Item {
        id: item
    }
}

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