Expose field of a sub-class to QML
Hi,
I have to expose into a QML widget fields from a set of nested classes like in the follows example:
Code:
{
Q_OBJECT
Q_PROPERTY(QString name READ getName
)
public:
...
private:
}
class B : public A
{
Q_OBJECT
Q_PROPERTY(int value READ getValue)
public:
B(int val);
int getValue();
private:
int _value;
}
// in another c
Q_INVOKABLE
QObject * getObjectOfTypeB
(){
return new B(1);
}
in QML:
Code:
var tmp = myModel.getObjectOfTypeB();
tmp.name // works
tmp.value // undefined
The filed from the top class works, while the field form the sub-class B is undefined.
What's wrong?
Thank you
Re: Expose field of a sub-class to QML
So far, everything looks good for me. Can you show the code where myModel is registered and instantiated?
Re: Expose field of a sub-class to QML
Sorry code was wrong.
In original cosa is missing a "Q_OBJECT" macro.