title: Binding a Qt model to an existing data-structure
body: <p>I've a tree-like polymorphic data-structure, where the nodes are instances of class Node (implemented by me) or any its subclass. My application heavily uses Boost and the nodes are actually represented by boost::shared_ptr type rather than <code>Node*</code>.</p>
  
  <p>Now, I want to create a Qt model to wrap my tree data-structure. Therefore I need a way to associate any model index with a node in my internal data structure. And here comes the problem:</p>
  
  <p>Qt supports two ways of doing it:</p>
  
  <p>First: </p>
  
  <p><code>QModelIndex QAbstractItemModel::createIndex ( int row, int column, void * ptr = 0 ) const</code> </p>
  
  <blockquote>
    <p>Creates a model index for the given
    row and column with the internal
    pointer ptr.</p>
  </blockquote>
  
  <p>And second: </p>
  
  <p><code>QModelIndex QAbstractItemModel::createIndex ( int row, int column, quint32 id ) const</code></p>
  
  <blockquote>
    <p>Creates a model index for the given
    row and column with the internal
    identifier, id.</p>
  </blockquote>
  
  <p>Ok, and how exactly should I associate the node in my case? There is no possibility to associate a shared_ptr with the model index... Yes, I know, I can receive a raw pointer from my shared_ptr and supply it to <code>CreateIndex()</code>, but it smells bad - seems too unsafe to me.</p>
  
  <p>Any ideas?</p>
  
  <p>By the way, I feel that in general Boost / Qt integration seems to be not trivial at least in the area of memory management.</p>
  
  <p>10x a lot.</p>