如何在QML中使用其他类枚举属性
给定的是一个包含枚举的类classa
:
class ClassA : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum EnumClassA {
};
Q_ENUM(EnumClassA)
};
第二类具有classa :: enumclassa
的属性:
#include <ClassA.h>
class ClassB : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(ClassA::EnumClassA value READ ...)
public:
};
这在qml中起作用(含义value 可以在QML中使用),但是当使用QMLINT/QMLSC编译器时,显示了以下消息:
error: Could not compile binding for value: Cannot generate efficient code for content pointer of non-QVariant wrapper type double of ClassB::value with type ClassA::EnumClassA
肮脏的修复程序可能是这样:
// replace "Q_PROPERTY(ClassA::EnumClassA value READ ...)" with:
Q_PROPERTY(int value READ ...)
但是将类型保留在属性中会更好。
是否可以修改枚举以便可以编译?
问候,
Given is a class ClassA
which contains an enum:
class ClassA : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum EnumClassA {
};
Q_ENUM(EnumClassA)
};
A second class has a property of ClassA::EnumClassA
:
#include <ClassA.h>
class ClassB : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(ClassA::EnumClassA value READ ...)
public:
};
This works in Qml (meaning the property value
can be used in Qml), but when using qmlint/qmlsc compiler the following message is shown:
error: Could not compile binding for value: Cannot generate efficient code for content pointer of non-QVariant wrapper type double of ClassB::value with type ClassA::EnumClassA
A dirty fix could be this:
// replace "Q_PROPERTY(ClassA::EnumClassA value READ ...)" with:
Q_PROPERTY(int value READ ...)
but it would be much nicer to keep the type in the property.
Is it possible to modify the enum so that it can be compiled?
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论