title: Qt5: How do I use QPointer with Forward Declared class
body: <p><strong>The problem:</strong>
  Replace <em>naked pointers</em> with <em>smart</em> <code>QPointers</code> and use them with forward declared classes.</p>
  
  <p><strong>Background:</strong>
  As advised by virtually all texts on modern C++, one should refrain from using <em>naked</em> pointers and use <em>smart</em> pointers instead. In the Qt toolkit there is a set of smart pointers available, with one of particular interest to me in this case: <code>QWeakPointer</code> (Qt 4) or <code>QPointer</code> (Qt 5), which is supposedly freely interchangeable with a <em>naked</em> pointer and is set to <code>NULL</code> when the respective object (derived from <code>QObject</code>) is deleted, thus helping prevent the all too common <em>dangling pointer</em> problem. Yet the requirement that the object pointed to by the <code>QPointer</code> be of a <code>QObject</code>-derived type prevents usage of forward declared classes.</p>
  
  <p><strong>The question: How do I combine <code>QPointer</code>-type variables with forward declared classes in the class header with forward declared types?</strong></p>
  
  <p>or</p>
  
  <p><strong>How do I avoid including the whole header file for an object for which I want to use the <code>QPointer</code>?</strong></p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>#pragma once
  #include &lt;QObject&gt;
  #include &lt;QPointer&gt;
  
  class MyQWidget; // Forward-declared class
  
  class SomeClass {
     QPointer&lt;MyQWidget&gt; m_myWidget;
  };
  </code></pre>
  
  <p><strong>Note:</strong> I've read through wuestion like this one: 
  <a href="https://stackoverflow.com/questions/2159390/in-c-is-it-possible-to-forward-declare-a-class-as-inheriting-from-another-cla">In C++, is it possible to forward declare a class as inheriting from another class?</a>. In my question, I'm looking for Qt-specific ways to overcome this limitation (or better design feature), if there are any.</p>
  
  <p><strong>Edit:</strong> My main compiler is MSVC 2010 and the error I get is </p>
  
  <pre><code>error C2079: 'MainWindow::m_test' uses undefined class 'QPointer&lt;T&gt;'
      with
      [
          T=MyQWidget
      ]
  </code></pre>