title: How and when to use Q_DECLARE_METATYPE
body: <p>I need to cast a QSqlRecord to QVariant and back throughout my project. In order to do so I added </p>
  
  <pre><code>Q_DECLARE_METATYPE(QSqlRecord);
  </code></pre>
  
  <p>in the .h files of the classes which require the casting.
  I also have a base class from which several children inherit, in this case I assume it is sufficient to include the Q_DECLARE_METATYPE only once in the base class. I therefore have for example:</p>
  
  <ul>
  <li>widgetBaseClass: declares metatype </li>
  <li>widgetChildClass1: inherits widgetBaseClass does not declare metatype</li>
  <li>widgetChildClass2: inherits widgetBaseClass does not declare metatype</li>
  <li>myTableModel: declares metatype</li>
  </ul>
  
  <p>When I try to run the program like this I get </p>
  
  <pre><code>Redefinition of 'QMetaTypeId&lt;QSqlRecord&gt;
  </code></pre>
  
  <p>from widgetBaseClass, pointing to the previous declaration in myTableModel. If on the other hand I remove the declaration I get:</p>
  
  <pre><code>static_assert failed "Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system");
  </code></pre>
  
  <p>From how I understand the workings of Q_DECLARE_METATYPE this means that if i declare it, it result in an error because it was already declared somewhere else, but if I don't declare it I cannot cast from QVariant, because it does not recognise the object as a valid QVariant, what am I missing?</p>