PDA

View Full Version : How do I use Q_PROPERTY to get data from my member variables



ayanda83
27th August 2014, 13:58
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
Q_PROPERTY(QString client_name READ getClientName); I want to use reflective programming to get the client's name. HOW CAN I DO THIS?

anda_skoa
27th August 2014, 14:08
Q_PROPERTY(QString client_name MEMBER client_name_member_variable)


Cheers,
_

ayanda83
27th August 2014, 14:13
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?

anda_skoa
27th August 2014, 14:54
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


myObject.client_name


In a C++ context you can access this form or getter-less property using the base property function


QString name = myObject->property("client_name").toString();


Cheers,
_