title: Managing QAbstractItemModel data in QSharedPointers
body: <p>In c++ Qt, I like managing my heap memory with <a href="http://doc.qt.io/qt-5/qsharedpointer.html" rel="nofollow">QSharedPointers</a>, but can/should one also use them for managing data in a <a href="http://doc.qt.io/qt-5/qabstractitemmodel.html" rel="nofollow">QAbstractItemModel</a>?</p>
  
  <p>For example, one can have a list of QStrings <code>QList&lt;QSharedPointer&lt;QString&gt; &gt; queue</code>.</p>
  
  <p>The problem is, that when implementing a <code>QSharedAbstractItemModel</code>, like the <code>QAbstractListModel</code>, you need to deal with raw pointers. For instance, the method <a href="http://doc.qt.io/qt-5/qabstractitemmodel.html#index" rel="nofollow">index</a> returns a <a href="http://doc.qt.io/qt-5/qmodelindex.html" rel="nofollow">QModelIndex</a> that takes a void pointer in the constructor, pointing to one of those QStrings on the heap. As soon as you create that object, you're working with the heap memory both managed and unmanaged.</p>
  
  <p>So if I store my selected item somewhere in a pointer and then clear my model, the data to that pointer gets deleted.</p>
  
  <p>So how does one deal with heap memory objects that you want to put in a <code>QAbstractItemModel</code></p>
  
  <p>I use qt 5.1.</p>