How do I use Q_PROPERTY to get data from my member variables
hi there. I have included Q_PROPERTY in my class and it works fine but I don't know how to retrieve member variable data using Q_PROPERTY instead of getters.
this is how the property looks like
Code:
Q_PROPERTY(QString client_name READ getClientName
);
I want to use reflective programming to get the client's name. HOW CAN I DO THIS?
Re: How do I use Q_PROPERTY to get data from my member variables
Code:
Q_PROPERTY(QString client_name MEMBER client_name_member_variable
)
Cheers,
_
Re: How do I use Q_PROPERTY to get data from my member variables
Will this give me the actual QString value contained in the variable client_name? and how do I call it from a function without using getters?
Re: How do I use Q_PROPERTY to get data from my member variables
The name after the type, in this case client_name, is the name of the property.
The name after MEMBER is the name of the variable.
They can of course be the same.
In a script context, e.g. QML, JavaScript, etc. you can access the property with the name
Code:
myObject.client_name
In a C++ context you can access this form or getter-less property using the base property function
Code:
QString name
= myObject
->property
("client_name").
toString();
Cheers,
_