title: I can't take QObject information from an object created as a subclass of QObject using reflection
body: <p>I have to create an instance of an object (subclass of <code>QObject</code>) using reflection. </p>
  
  <p>Let's suppose this object is <code>MyQObject</code> and have declared the following properties using the <code>Q_PROPERTY</code> macro: <code>MyQObject1* p1</code>, <code>MyQObject2* p2</code>, <code>MyQObject3* p3</code>, ...</p>
  
  <p>Let's say I have this function to do that:</p>
  
  <pre><code>    QObject* Manager::createInstanceOf(const QMetaObject* c, QList&lt;const char*&gt; paramsNames, QList&lt;QObject*&gt; oparams) {
      QObject* instance = (QObject*) c-&gt;newInstance();
  
          for(int i = 0; i &lt; paramsNames.length(); i++) {
              QVariant variant = QVariant::fromValue(oparams[i]);
              instance-&gt;setProperty(paramsNames[i], variant);
          }
      return instance;
     }
  </code></pre>
  
  <p>where:</p>
  
  <p><code>c</code> is the <code>QMetaObject*</code> associated with <code>MyQObject</code>.</p>
  
  <p><code>paramsNames</code> is a <code>QList&lt;const char*&gt;</code> containing the names of the properties declared in the object's class definition through the <code>Q_PROPERTY</code> macro. In this example, <code>QList</code> contains: <code>"MyQObject1"</code>, <code>"MyQObject2"</code>, <code>"MyQObject3"</code>, ...</p>
  
  <p><code>oparams</code> is a <code>QList&lt;QObject*&gt;</code> containing the properties of the object already instantiated. None of them is a <code>QObject</code> per se, but a subclass of <code>QObject</code>, and might not be all the same. In this example, a <code>QList</code> containing a instance for <code>MyQObject1</code>, <code>MyQObject2</code>, <code>MyQObject3</code>...</p>
  
  <p>My problem is that although the instance of <code>MyQObject</code> is created and the types were registered using <code>Q_DECLARE_METATYPE</code> macro and <code>qRegisterMetaType</code>, I can't access to any of the properties' methods associated with <code>QObject</code> without getting segfault. In few words, I can't do:</p>
  
  <pre><code>myQObjectInstance-&gt;property("p1").value&lt;MyQObject1*&gt;()-&gt;metaObject();
  </code></pre>
  
  <p>but I can access without problem other methods of the properties that are not from <code>QObject</code>. For example:</p>
  
  <pre><code>myQObjectInstance-&gt;property("p1").value&lt;MyQObject1*&gt;()-&gt;toString();
  </code></pre>
  
  <p>I realized that if I cast the property before doing the <code>setProperty</code>, my problem can be solved partially: </p>
  
  <pre><code>QVariant::fromValue((MyQObject1*) oparams[0]);
  </code></pre>
  
  <p>It seems to be that if the property is not set as the specific subclass of <code>QObject</code> as it was created, but casted as its superclass (when inserted in <code>oparams</code> <code>QList</code> they are automatically casted), is what causes the problem.</p>
  
  <p>Due to the different types of the properties (<code>MyQObject1</code>, <code>MyQObject2</code>, <code>MyQObject3</code>,...) I can't cast one by one because I don't know this information at compile time. </p>
  
  <p>So, any ideas?</p>
  
  <p>I will really appreciate your help. Thanks.</p>