title: How to ensure qRegisterMetaType is run when my shared library is loaded?
body: <p>I've created a <code>QObject</code>-derived class that looks something like this:</p>
  
  <pre><code>namespace MyNamespace
  {
      class MyClass : public QObject
      {
          Q_OBJECT
  
          public:
  
              enum MyEnum 
              {
                  Item1,
                  Item2
              };
  
          Q_SIGNALS:
  
              void mySignal(MyEnum type);
      };
  }
  </code></pre>
  
  <p><code>MyEnum</code> needs to be registered with <code>qRegisterMetaType</code>.</p>
  
  <p>Here's the twist: this class is contained in a shared library, and therefore I want to avoid instructing anyone using my library to call <code>qRegisterMetaType</code>. Instead, the <code>enum</code> should be registered as soon as the shared library is loaded.</p>
  
  <p>Is there any way to do this? I need the solution to work with Qt 5 (I am not currently supporting Qt 4.x). Qt 5.1 introduces the <a href="http://doc-snapshot.qt-project.org/qt5-stable/qtcore/qglobalstatic.html" rel="nofollow"><code>QGlobalStatic</code></a> class, but I need to maintain compatibility with Qt 5.0.</p>
  
  <p>If I were to use <code>Q_DECLARE_METATYPE</code>, it would need to go outside of the namespace. It would look something like this:</p>
  
  <pre><code>Q_DECLARE_METATYPE(MyNamespace::MyClass::MyEnum)
  </code></pre>
  
  <p>However, the <code>Q_DECLARE_METATYPE</code> macro would expand to the following call to <code>qRegisterMetaType</code>:</p>
  
  <pre><code>qRegisterMetaType&lt; MyNamespace::MyClass::MyEnum &gt;("MyNamespace::MyClass::MyEnum",
      reinterpret_cast&lt; MyNamespace::MyClass::MyEnum *&gt;(quintptr(-1)));
  </code></pre>
  
  <p>So the <code>enum</code> would be registered with the full namespace qualifiers but the signal would be registered as <code>mySignal(MyEnum)</code>. Therefore, the type <code>MyEnum</code> would not be registered with Qt since only <code>MyNamespace::MyClass::MyEnum</code> was registered.</p>