受限类型
qmllint 将此警告类别标记为[restricted-type] 。
您无法从这里访问未定义作用域的枚举
发生了什么?
您通过枚举类型名称访问了在 C++ 中定义的枚举的值。
为什么这样不好?
在 C++ 中定义的无作用域枚举不能通过其枚举类型名称进行访问。运行时这些枚举的值将被视为未定义。
示例
其中 MyClass 定义为
class MyClass: public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum Hello { World };
Q_ENUM(Hello);
...
};要解决此警告,请从 QML 代码中移除多余的枚举类型名:
如果您是该枚举的作者,也可以修改枚举定义,改用枚举类,而无需更改 QML 代码:
class MyClass: public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum class Hello { World };
Q_ENUM(Hello);
...
};注意:您 可以在此处找到有关枚举类型注册的更多信息。
© 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.