Hi,
I have a QAbstracTableModel that provide data for a QTableView. From time to time my model is reset, so when the internal data is about to be changed I call beginResetModel() then I change the internal data and finally calls reset() and endResetModel().

The form holding the respective view has the slotholdActiveFlightSelectio() connected to modelAboutToReset() and the slot resetActiveFlightSelection() connected to modelReset().
When the slot triggered by modelAboutToReset() is called I basically store the callsign of a item.
When the slot triggered by modelReset() is called I search for the callsign and then I try to select the correponding item at the new view.

this is the code:
Qt Code:
  1. void FlightTables::holdActiveFlightSelection()
  2. {
  3. int k;
  4. selectedActiveFlights.clear();
  5. QModelIndexList selectedRows = activeSelectionModel->selectedRows();
  6. if(selectedRows.size() == 0) return;
  7. for(k=0;k<selectedRows.size();k++)
  8. {
  9. selectedActiveFlights.append(activeModel->data(selectedRows.at(k),Qt::DisplayRole).toString());
  10. }
  11. }
  12.  
  13. void FlightTables::resetActiveFlightSelection()
  14. {
  15. int k;
  16. QString callsign;
  17. if(selectedActiveFlights.size() == 0) return;
  18. activeSelectionModel = ui->activeFlightTableView->selectionModel();
  19. for(k=0;k < activeModel->rowCount();k++)
  20. {
  21. QModelIndex tmpIndex = activeModel->index(k,0);
  22. QItemSelection selection;
  23. callsign = activeModel->data(tmpIndex,Qt::DisplayRole).toString();
  24. if(selectedActiveFlights.contains(callsign))
  25. {
  26. selection.select(tmpIndex,tmpIndex);
  27. activeSelectionModel->select(selection,QItemSelectionModel::Select|QItemSelectionModel::Rows);
  28. //activeSelectionModel->select(tmpIndex,QItemSelectionModel::Select|QItemSelectionmodel::Rows);
  29.  
  30. }
  31. }
  32. }
To copy to clipboard, switch view to plain text mode 
I am holding the callsigns before the model reset and searching for them in the new model, but when i try to paint the selecion at the QTableView by activeSelectionModel nothing happens?!
I am not sure about the diference of calling:
void QItemSelectionModel::select ( const QModelIndex & index, QItemSelectionModel::SelectionFlags command )
or
void QItemSelectionModel::select ( const QItemSelection & selection, QItemSelectionModel::SelectionFlags command )