Implementing your own property system (Qt-like)

I want to implement my own simple property system (C++) similiar to one provided by Qt's Q_PROPERTY. The problem is that Qt's properties doesn't work from inside macros which I'm trying to use to add some additional functionality above properties. The aim is to be able to declare a property and automatically get access both through properties string name representation and regular methods:

MY_PROPERTY(QString, Name)
...
getObject()->setProperty("Name", "John");
...
myObject->setName("John");
QString name = myObject->getName();

I want to add all the needed functionality with a single line but the following code will not work, since MOC doesn't expand macros:

#define MY_PROPERTY(type, name)\
Q_PROPERTY(type name READ name WRITE change##name)\
\
void set##name(type param)\
{\
    m_##name = param;\

    DO SOMETHING
}\  

Please advice any good books/articles on this topic.

Answers


most (>95%) condition, Qt Propery System is enough, if you really want to add something on yourself property when its setting or getting, you can use Qt signal/slot System to do this.

if you finally still want to do you own Property System, I think the best reference is Qt source code, isn't it?


Need Your Help

How to detect loss of internet reachability when wifi source loses connection?

iphone ios objective-c reachability

I am trying hard to get the authentic internet connectivity status. I have used Apple's Reachability but it's only giving me the status of wifi connectivity i.e. not covering the case when the devi...

Migrating existing cakephp 3.0 database to postgres from mysql

php mysql database postgresql cakephp

I am in the process of migrating a cakephp 3.0 database from mysql to postgress. I used this tool for the database migration and it worked beautifully. After that I changed the config file as shown...