【发布时间】:2012-09-15 07:26:25
【问题描述】:
我有一个自定义类型的属性。
class foo : public QObject {
Q_OBJECT
Q_PROPERTY(Custom x READ x WRITE set_x)
public:
void set_x(Custom &x) { /*whatnot*/}
}
QJson 有效地调用了以下动态赋值:
((QObject*)&foo_instance)->setProperty("x", QVariant(QString("something-from-json")))
返回 false,如 Qt 中所述:
如果值与属性的类型不兼容,则属性不变,返回false。
如何将其填充到我的自定义值中?明确定义一个附加函数void set_x(QString) 或void set_x(QVariant) 是不可能的,因为属性系统不知道这个访问器。
另外,类型兼容性在哪里检查? - 程序控制永远不会到达
int foo::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
元对象编译器生成的函数..
如何使Custom 与这些类型兼容?
【问题讨论】:
-
对已接受答案的评论实际上为我确定了这一点。
标签: qt properties metaobject