title: How to properly use qRegisterMetaType on a class derived from QObject?
body: <p>I've been searching far and wide for an answer to this but to no avail. My lament is as follows:</p>
  
  <p>I have a <code>ClassA</code> that roughly looks like this:</p>
  
  <pre><code>class ClassA : public QObject {
      Q_OBJECT
  public:
      ClassA() { mName = "lol"; }
      ~ClassA();
      void ShowName() { std::cout &lt;&lt; mName &lt;&lt; std::endl; }
      std::string mName;
  };
  </code></pre>
  
  <p>Of course, since I use moc, this class is actually split into cpp and hpp in my project but that part is not the issue here.</p>
  
  <p>Please note that I do not use <code>Q_DECLARE_METATYPE</code> on purpose because I don't actually need its features (QVariant expansion) right now. I only care about runtime instantiation.</p>
  
  <p>The issue here is that <code>Q_OBJECT</code> forbids the copy and assignment constructors. Due to that, I have to apply <code>qRegisterMetaType</code> not to <code>ClassA</code> itself but to <code>ClassA*</code> which seems to work fine at first glance.</p>
  
  <p>Now, I want to create this class dynamically at runtime from a string and run the method <code>ShowName()</code>. I'm doing that like this:</p>
  
  <pre><code>int main() {
      qRegisterMetaType&lt;ClassA*&gt;("ClassA*");
  
      int id = QMetaType::type("ClassA*");
      std::cout &lt;&lt; "meta id: " &lt;&lt; id &lt;&lt; std::endl; // Outputs correct generated user id (not 0)
  
      ClassA* myclass = static_cast&lt;ClassA*&gt;(QMetaType::construct(id));
      myclass-&gt;ShowName(); // Segfaults, oh dear
  
      return 0;
  }
  </code></pre>
  
  <p>Now, there is my issue. I don't seem to actually have a correctly constructed object there.</p>
  
  <p>If we change the class to look like this:</p>
  
  <pre><code>class ClassA : public QObject {
      Q_OBJECT
  public:
      ClassA() { mName = "lol"; }
      ClassA(const ClassA&amp; other) { assert(false &amp;&amp; "DONT EVER USE THIS"); }
      ~ClassA();
      void ShowName() { std::cout &lt;&lt; mName &lt;&lt; std::endl; }
      std::string mName;
  };
  </code></pre>
  
  <p>then we can change our program accordingly to:</p>
  
  <pre><code>int main() {
      qRegisterMetaType&lt;ClassA&gt;("ClassA");
  
      int id = QMetaType::type("ClassA");
      std::cout &lt;&lt; "meta id: " &lt;&lt; id &lt;&lt; std::endl; // Outputs correct generated user id (not 0)
  
      ClassA* myclass = static_cast&lt;ClassA*&gt;(QMetaType::construct(id));
      myclass-&gt;ShowName(); // "lol", yay
  
      return 0;
  }
  </code></pre>
  
  <p>Obviously I could just use my fake overwritten copy constructor but it doesn't feel right and Qt suggests against that and instead suggests the use of pointers to QObjects only.</p>
  
  <p>Does anyone see what's wrong here? Also, I am aware there are similar questions on SO but none of them tackle this exact problem.</p>