title: Understanding Qt view-model architecture: when to create and how to cleanup indexes in QAbstractItemModel implementation?
body: <p>I'm currently migrating my project from <code>QTreeWidget</code> to <code>QtreeView</code>, and have a lot of problems caused by poor understanding of the Qt model-view design. So far I couldn't find answers even in Qt examples.</p>
  
  <p>I've implemented my <code>QAbstractItemModel</code>. I'm returning strings to be viewed in the <code>QTreeView</code> through <code>data</code> method. Now, the underlying data will change in runtime. To handle this my model is subscribed to a notification that does <code>emit dataChanged(index(0,0), index(rowCount() - 1, LastColumn));</code>. The question is: how to create and cleanup <code>QModelIndex</code> objects? One of the Qt examples reimplements <code>index</code> method, so I did the same:</p>
  
  <pre><code>QModelIndex CFileListModel::index(int row, int column, const QModelIndex &amp;/*parent*/) const
  {
      QModelIndex index = createIndex(row, column);
      return index;
  }
  </code></pre>
  
  <p>However, data is static in that example and in my case it changes at runtime. Is my <code>index</code> implemetation correct? What if <code>index</code> is called more than once for the same coordinates? Do I need to somehow cleanup old indexes before emitting <code>dataChanged</code>?</p>