枚举不是类型
此警告类别由 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.