Hi everyone,
I want to use qt property(Q_property) for dynamically get/set value in a class. But I am not able to get how to use it.

myproperty.h :
Qt Code:
  1. #include <QObject>
  2.  
  3. class MyProperty : public QObject
  4. {
  5. Q_OBJECT
  6. Q_PROPERTY(QString name READ name WRITE setName)
  7.  
  8. public:
  9. MyProperty(QObject *parent = 0);
  10. ~MyProperty(){}
  11.  
  12. QString name();
  13. void setName(QString name);
  14.  
  15. private:
  16. QString m_name;
  17. };
To copy to clipboard, switch view to plain text mode 

myproperty.cpp :
Qt Code:
  1. MyProperty::MyProperty(QObject *parent)
  2. : QObject(parent)
  3. {
  4. }
  5.  
  6. QString MyProperty::name()
  7. {
  8. return m_name;
  9. }
  10.  
  11. void MyProperty::setName(QString name)
  12. {
  13. m_name = name;
  14. }
To copy to clipboard, switch view to plain text mode 

Property list:
Qt Code:
  1. MyProperty obj;
  2. const QList<QByteArray> pList = obj.dynamicPropertyNames();
  3. qDebug()<<pList.size(); // size is 0
To copy to clipboard, switch view to plain text mode 

main.cpp:
Qt Code:
  1. QApplication a(argc, argv);
  2.  
  3. MainWindow w;
  4. w.show();
  5.  
  6. return a.exec();
To copy to clipboard, switch view to plain text mode 

Is it the correct way to use a property ? Please help me.

thanks.