在根元素之外声明枚举

此警告类别由 qmllint 拼写[non-root-enum]

在根元素之外声明的枚举

发生了什么事?

在组件根元素之外声明了一个枚举。

为什么会这样?

因为它无法访问。枚举的访问方式是 <组件名>.<可选枚举名>.<枚举项>。如果枚举不在组件的根元素中,那么这种查找将不起作用。

示例

// Main.qml
import QtQuick

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

要修复此警告,请将枚举移至组件根目录:

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