title: Qt QMetaObjects and casting from QWidget to QObject
body: <p>Im trying to make the code which reads xml files and deserialize various qt controls from this xml, and im doing this using QDomDocument, and i want to get the QLlist from my deserealization method. And im having a bit of troubles, here is some code of the template class (.h) file:</p>
  
  <pre><code> QList&lt;T*&gt; deserialize(QIODevice *input)
   {
  
          QList&lt;T*&gt; objects = QList&lt;T*&gt;();
  
  
          if(_deserializeObject(input, objects)) 
              return objects;
  
      }
      bool _deserializeObjects(QIODevice* input, QList&lt;QObject*&gt;&amp; list);
  </code></pre>
  
  <p>and my .cpp file with deserialize method, here im reading the control tags from file:</p>
  
  <pre><code>bool Serializer::_deserializeObjects(QIODevice* input,  QList&lt;QObject *&gt; &amp;objects)
  {
      QDomDocument doc;
      if (!doc.setContent(input))
          return false;
      QDomElement root= doc.documentElement();
  
      for(int j = 0; j &lt; root.childNodes().length();j++)
      {
  
  
           QObject* object;
           qDebug() &lt;&lt; root.tagName();
          if(root.tagName().contains("QGroupBox"))   //  &lt;------- Here i need to determine which control i need to process.
          {
             ????  
          }
  
         qDebug () &lt;&lt; object-&gt;metaObject()-&gt;className();
         qDebug() &lt;&lt; object-&gt;metaObject()-&gt;propertyCount();
  
      for(int i = 0; i &lt; object-&gt;metaObject()-&gt;propertyCount(); i++)
      {
  
          object-&gt;metaObject()-&gt;cast()
  
          QMetaProperty prop = object-&gt;metaObject()-&gt;property(i);
  
  
              QString propName = prop.name();
               if(propName == "objectName")
                   continue;
               QDomNodeList nodeList = root.elementsByTagName(propName);
               if(nodeList.length() &lt; 1)
                  continue;
                QDomNode node = nodeList.at(0);
                QVariant value = object-&gt;property(propName.toLatin1().data());
                QString v = node.toElement().text();
  
                if(propName == "x")
                {
                    x = v.toInt();
                }
                else if(propName == "y")
                {
                    y = v.toInt();
                }
                else if(propName == "width")
                {
                    width = v.toInt();
                }
                else if(propName == "height")
                {
                    height = v.toInt();
                }
                if(propName == "geometry")
                {
                     continue;
  
                }
                object-&gt;setProperty(propName.toLatin1().data(), QVariant(v));
  
  
      }
      object-&gt;setProperty("geometry",QVariant(QRect(x,y,width,height)));
      objects.push_back(object);
  
      }
      return true;
  }
  </code></pre>
  
  <p>In this part</p>
  
  <pre><code>  if(root.tagName().contains("QGroupBox"))   //  &lt;------- Here i need to determine which control i need to process.
              {
                 ????  
              }
  
             qDebug () &lt;&lt; object-&gt;metaObject()-&gt;className();
             qDebug() &lt;&lt; object-&gt;metaObject()-&gt;propertyCount();
  
          for(int i = 0; i &lt; object-&gt;metaObject()-&gt;propertyCount(); i++)
          {
            ...
          }
  </code></pre>
  
  <p>I want to actually somehow get the type of the control by name, so the question is, can i cast QGroupBox to QObject saving the QGroupBox properties so QObject metaObject class name would be QGroupBox, so i can pass all this properties? Because i don't want to make the loops for each control type. Also i when i got the result like so:</p>
  
  <pre><code>     QList&lt;QObject *&gt; ds = s.deserialize&lt;Object&gt;((QIODevice*)&amp;f);
  </code></pre>
  
  <p>Can i then just pass all QObjects in a loop and using QMetaObject class name and using qobject_cast cast each object to QPushButton,QLabel etc.?</p>