title: How to create a deep copy of a QList (Qt 4.8)
body: <p>I'm trying to make a deep copy of a QList, I'm using Qt 4.8. In the code below <code>mData</code> is a <code>QList&lt;unsigned char&gt;</code> member variable of the <code>Test</code> class.</p>
  
  <p>In first instance I thought the code below should work, however diving deeper in Qt's implicitly shared (i.e. copy-on-write) concept, I'm doubting if this is the correct way to go.</p>
  
  <pre><code>Test::Test(QList&lt;unsigned char&gt; &amp;aData) {
      mData.QList(aData);
  }
  </code></pre>
  
  <p>According Qt, </p>
  
  <blockquote>
    <p>QList::QList(const QList &amp; other)</p>
    
    <p>Constructs a copy of other.</p>
    
    <p>This operation takes constant time, because QList is implicitly
    shared. This makes returning a QList from a function very fast. If a
    shared instance is modified, it will be copied (copy-on-write), and
    that takes linear time.</p>
  </blockquote>
  
  <p>I want to ensure that if <code>aData</code> goes out of scope or if the content of <code>aData</code> is modified, this doesn't change the content of <code>mData</code>. Is this possible without having to iterate and copy each list entry separately?</p>
  
  <p>Note: this is not a duplicate of <a href="https://stackoverflow.com/questions/1277121/qt-4-5-qlistqlistconst-qlist-is-this-a-deep-copy-constructor">Qt 4.5 - QList::QList(const QList&amp;) - is this a deep copy constructor?</a> because this question implicitly asks <strong>how</strong> to create a deep copy" instead of <strong>if</strong> something is a deep copy.</p>