Hello, I'm having a slight problem with model/proxy/view -combo.

As I call beginRemoveRows(.., FIRST, LAST) to remove all items from the model I get selectionChanged(..) from the View's SelectionModel (assuming I had some items selected). The receiving slot then results in following functions being called

Qt Code:
  1. void FileVersionManager::installSelectionChanged(
  2. const QItemSelection& selected, const QItemSelection& deselected)
  3. {
  4. installSet_.listSelectionChanged(selected, deselected); // keep track of # of selected rows
  5.  
  6. if (installSet_.selectedRowCount == 1)
  7. {
  8. hoverInstallInfo_ = false;
  9. setActiveInstallFromFile(installSet_.selectedFile());
  10. }
  11. else
  12. {
  13. hoverInstallInfo_ = true;
  14. setActiveInstallFromFile(installSet_.hoverFile()); // <-- relevant call
  15. }
  16. updateInstallActions();
  17. }
  18.  
  19.  
  20. FileNode* FileSet::hoverFile() const
  21. {
  22. QPoint pnt = view->viewport()->mapFromGlobal(QCursor::pos());
  23. return proxy->mapToFile(view->indexAt(pnt));
  24. }
  25.  
  26. FileNode* FileSetSortFilterProxyModel::mapToFile(const QModelIndex& index) const
  27. {
  28. return model_.mapToFile(mapToSource(index));
  29. }
  30.  
  31. FileNode* InstallSetModel::mapToFile(const QModelIndex& index) const
  32. {
  33. if (index.isValid())
  34. return static_cast<FileNode*>(index.internalPointer());
  35. return 0;
  36. }
To copy to clipboard, switch view to plain text mode 

The problem is that the FileNode* I get is not NULL as I'd hope it to be due to beginRemoveRows() call. This will eventually segfault later due to the "deleted" file being set where it shouldn't.

Is it normal behaviour that the view returns valid QModelIndex even when the underlying model's all rows are being removed ? Or should I just avoid calling indexAt() or any other functions that return indexes from the views until after endRemoveRows() ?

Thanks.