View Full Version : Use QIterator on TreeView's model

12th December 2009, 18:31
What is the best way to define and use a QIterator on a QTreeView model? I want to iterate through all the items in a QTreeView's model, and I'm having some trouble figuring out the best way to turn a custom model based on QAbstractItemModel into a QListView in order to create the iterator. I'm using an example based more/less on SimpleTreeView in the QT Examples. Thanks in advance for your help.

12th December 2009, 20:46
You don't turn a model into the view. The view's data is held in the model so if you want to iterate the items of the view, you just access the model.

for(int i = 0; i< tree->model()->rowCount(); i++){
QModelIndex index = tree->index(i, 0); // column no 0