You need it when working with a tree model. Compare:
Qt Code:
  1. #include <QtGui>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  
  6. QApplication app(argc, argv);
  7.  
  8. QStandardItem *parentItem = model.invisibleRootItem();
  9. for (int i = 0; i < 5; ++i)
  10. {
  11. QStandardItem *item = new QStandardItem(QString("Root %1").arg(i));
  12. for (int j = 0; j < 5; ++j)
  13. {
  14. QStandardItem *itemSub = new QStandardItem(QString("%1:%2").arg(i).arg(j));
  15. item->appendRow(itemSub);
  16. }
  17. parentItem->appendRow(item);
  18. }
  19.  
  20. b.setModel(&model);
  21. b.show();
  22.  
  23. b2.setModel(&model);
  24. b2.setRootModelIndex(model.index(1,0));
  25. b2.show();
  26.  
  27. return app.exec();
  28. }
To copy to clipboard, switch view to plain text mode