title: How do I delete all items from a QStandardItemModel
body: <p>I am having some trouble with my <code>QStandardItemModel</code>.
  What I want to do is add a list to my model, and when the list is updated, I pass the new list in the parameter, clear the old model and add the new list.
  This sounds simple enough but i'm coming across a bug that i can't figure out. When i add the first list to the model there is no problem, but when i add the second one, the first one is successfully deleted (I can see that in the console) but then the application crashes.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>void MyModel::updateList(QList&lt;QStandardItem*&gt; list)
  {
  
      // Delete current model
  
      int rows = rowCount();
      for (int i = 0 ; i &lt; rows ; i++)
      {
          if(item(0)-&gt;hasChildren())
          {
              int children = item(0)-&gt;rowCount();
              for (int j = 0 ; j &lt; children ; j++)
              {
                  QString name = item(0)-&gt;child(0)-&gt;accessibleText();
                  qDebug()&lt;&lt;(name + QLatin1String("\tremoved"));
                  item(0)-&gt;removeRow(0);
              }
          }
          QString itemRemoved = item(0)-&gt;accessibleText();
          qDebug()&lt;&lt;(itemRemoved + QLatin1String("\tremoved"));
          removeRow(0);
      }
  
  
      // Add new list to model
  
      for(int j=0 ; j&lt;list.count() ; j++)
      {
          appendRow(list[j]);
          qDebug()&lt;&lt; (list[j]-&gt;accessibleText() + tr(" ADDED"));
      }
  
      printf("List UPDATED \n");
  }
  </code></pre>
  
  <p>Obviously i have tried using the method <code>clear();</code> instead of deleting row by row but it has the same result.</p>
  
  <p>I don't understand why this code doesn't work.</p>
  
  <p>If somebody can shed some light on the matter i would be very grateful. </p>