PDA

View Full Version : Hot to get a QModelIndexList from a model?



brazso
16th January 2009, 09:48
I would like to get a QModelIndexList from a QStandartItemModel object. Latter is a table and I need the indices of its first columns of all (not only the selected!) rows. I may use QAbstractItemModel::match method, but is not there a more efficient way to get all indices of a model object?

For the time being I use this awkward way to get it:


QModelIndexList indices;
for (int i=0; i<model->rowCount(); i++){
indices << model->indexFromItem(model->item(i, 0));
}

wysota
16th January 2009, 12:10
for(int i=0;i<model->rowCount();i++){
QModelIndex index = model->index(i,0);
}

You can use the index inside the for loop or add it to a list of indices and use the list afterwards. Just remember not to store it anywhere for later use.