枚举不是类型
qmllint 将此警告类别拼写为[enums-are-not-types] 。
QML 枚举不是类型
发生了什么?
您在类型注释中使用了枚举名称。
为什么这样不好?
枚举名称不是类型,因此不能用于类型注解。QML 工具无法使用该类型注解:编译器无法将此方法编译为 C++,qmllint同样 QML Language Server 也无法分析该方法。
示例
// Main.qml
import QtQuick
Item {
enum HelloWorld { Hello, World }
function f(e: Main.HelloWorld): bool {
return e == World
}
}要解决此警告,请将类型注解中的枚举名称替换为底层类型,例如,如果底层类型最多需要 32 位,则使用 `int `;否则,例如使用 `double`。
import QtQuick
Item {
enum HelloWorld { Hello, World }
function f(e: int): bool {
return e === World
}
}© 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.