C++ class members from qml
-
Hello !
I want to read Q_PROPERTY of a member object, and display it in qml.I have a class A witch has a private member object from class B like this :
class A
{
//Q_PROPERTY QString localS = "localOK" this will work in qml : a.getLocalS
private:
B *b // class B has Q_PROPERTY QString testStr = "test" and getTestStr() getter
}
In main.cpp, i set an instance of class 'A' in contextProperties
A a;
engine.rootContext()->setContextProperty("a",&a);Now in main.qml i want to read b objects testStr
Text{
//text : a.getLocalS this is OK
text:a.b.getTestStr // this will not work
}How can i access b by a ?
Is it possible to create Q_Property in A, witch returns my b ?
Q_PROPERTY(B myB READ getB )
*B getB(){
return b;
}and then do :
Text{
text:a.getB.getTestStr
}thank you in advance
Levon -
@medyakovvit Thx very much this is exactly what i was reading now ! :)
I will try this tomorrow -
Hi, @LeLev
From Qt's doc:if the class itself is to be used as a method parameter or property, or if one of its enum types is to be used in this way — then the class may need to be registered.
-
@medyakovvit Thx very much this is exactly what i was reading now ! :)
I will try this tomorrow