QModelIndexList selectedIndexes = treeView->selectionModel()->selectedIndexes(); for(const QModelIndex& index : selectedIndexes){ // Do something with each selected index }
QModelIndexList matchingIndexes = model->match(model->index(0, 0), Qt::UserRole, QVariant("Matching Data"), -1, Qt::MatchExactly); for(const QModelIndex& index : matchingIndexes){ // Do something with each matching index }This code uses the model's match() function to find all QModelIndexes that match a certain data value. It searches all items in the model, starting at the root index (0,0). The package library for QModelIndexList is part of the Qt core library.