[Solved] setContextProperty and Inheritance
-
Hi,
I have an UiHandlerClass which has a lot of Function which are the same except from the name string in setContextProperty.
As the class got to big anyway i decided to split the class in 2 classes which share a lot of code. So i thought of an abstractClass which
has a function say: setStation() and in the both subclasses i can call this function. But the need to set differnet Properties. Thus i wanted to know if there is a way that in subclasses i can just define the name for the property withou changing the parent code.I hope of something like this
@
//file parent
#define NAME "parent"class Parent{
public:
setStation(){
//some code
context->setContextProperty(NAME,someObj);
}
protected:
SomeType someObj;
}//in Child file
#define NAME "childName"
class Child : public Parent{}
@such that qml can see properties with childName
but with defines it doesn't work..I there some clean way to do this?
-
You should create variable in Parent class and initialize its value in constructors with different values in Parent and Child. Overall learn about C++ inheritance.
-
Ah nice, I had the idea of doing it with variables but I somehow thought these Strings need to be fixed at compile-time, thus i didn't even try it.
This is actually very cool thank you.