title: What is wrong with this Qt code?
body: <p>I was reading MVC tutorial and wanted to try out the code, but for some reason (which I'm not able to figure out) it is not working. </p>
  
  <p>This code is suppose to show contents of current directory in QListWidget. </p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QFileSystemModel&gt;
  #include &lt;QModelIndex&gt;
  #include &lt;QListWidget&gt;
  #include &lt;QListView&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      QFileSystemModel *model = new QFileSystemModel;
      QString dir = QDir::currentPath();
      model-&gt;setRootPath(dir);
      QModelIndex parentIndex = model-&gt;index(dir);
      int numRows = model-&gt;rowCount(parentIndex);
      QListWidget *list = new QListWidget;
      QListWidgetItem *newItem = new QListWidgetItem;
  
      for(int row = 0; row &lt; numRows; ++row) {
          QModelIndex index = model-&gt;index(row, 0, parentIndex);
          QString text = model-&gt;data(index, Qt::DisplayRole).toString();
          newItem-&gt;setText(text);
          list-&gt;insertItem(row, newItem);
      }
  
      list-&gt;show();
      return a.exec();
  }
  </code></pre>