I have 2 different C++ objects using Q_PROPERTY and Q_INVOKABLE for a function, in my qml file I have this:
include MyObject 1.0 //from c++
incluce MyInvokable 1.0 //from c++
property variant myVariant
MyObject{
id:myObject
}
MyInvokable{
id: myInvokable
}
onCallFunction:{
myVariant = myObject;
myInvocable.invokableFunction( myVariant )
}
At MyInvokable function I can’t get the value of MyObject:
void MyInvocable::invocableFunction(QVariant variant)
{
MyObject myObject = qvariant_cast<MyObject>(variant) ; //cant convert to MyObject
qDebug() << "foo: " << myObject.foo();
}
MyObject has the macro
Q_DECLARE_METATYPE(MyObject);
How can I convert QVariant to my custom Object ?
Regards
↧