title: Qt/C++ How does one iterate QMetaObject's properties / data types of a given Class Object?
body: <p>In C#/Java I use reflection to read in the properties of a class.  I have made an attempt using Qt, and don't know if I'm going about solving my problem correctly.</p>
  
  <p>A simple Person Class Header, note the 3 properties (id, fname, lname)</p>
  
  <pre><code>#ifndef PERSON_H
  #define PERSON_H
  
  #include &lt;QObject&gt;
  
  class Person : public QObject
  {
      Q_OBJECT
  public:
      explicit Person(QObject *parent = 0);
  
      int id;
  
      QString fname;
  
      QString lname;
  
      /* ... 50+ more properties here */
  
      int getId() const;
      void setId(int value);
  
      QString getFname() const;
      void setFname(const QString &amp;value);
  
      QString getLname() const;
      void setLname(const QString &amp;value);
  
      /* ... 50+ more getter/setters here */
  
  signals:
  
  public slots:
  };
  
  #endif // PERSON_H
  </code></pre>
  
  <p>With the following code snippet, I would like to print the properties of the Person class.  The intent would be to later loop through a collection of objects and load a QMap with values depending if the class property has an assigned value.</p>
  
  <pre><code>Person p;
  const QMetaObject *metaObj = p.metaObject();
  qDebug() &lt;&lt; "class name: " &lt;&lt; metaObj-&gt;className();
  qDebug() &lt;&lt; "method count: " &lt;&lt; metaObj-&gt;methodCount();
  qDebug() &lt;&lt; "property count: " &lt;&lt; metaObj-&gt;propertyCount();
  qDebug() &lt;&lt; "ClassInfo count: " &lt;&lt; metaObj-&gt;classInfoCount();
  
  qDebug() &lt;&lt; "properties: ";
  for (int i = metaObj-&gt;propertyOffset(); i &lt; metaObj-&gt;propertyCount(); ++i)
      qDebug() &lt;&lt; metaObj-&gt;property(i).type() &lt;&lt; " " &lt;&lt; metaObj-&gt;property(i).typeName();
  </code></pre>
  
  <p>However, the outputs are:</p>
  
  <pre><code>class name:  Person
  method count:  5
  property count:  1
  ClassInfo count:  0
  Constructor count:  1
  properties:
  </code></pre>
  
  <p>These numbers make no sense and no properties are displayed.</p>