I have a QDirModel in a QDirTree. I select several files in this view and try to delete them with with following routine:

Qt Code:
  1. foreach(QModelIndex index,selectionModel()->selectedIndexes()){
  2. if(index.isValid() && index.column()==0){
  3. if(dirModel->isReadOnly()){
  4. return;
  5. }
  6. // Crashes here the second time.
  7. if(dirModel->isDir(index)){
  8. dirModel->rmdir(index);
  9. }else{
  10. dirModel->remove(index);
  11. }
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

The first file is deleted normaly, the second time the foreach loop is traversed the code segfaults in 'if(dirModel->isDir(index))'. The core tells me:

Qt Code:
  1. #0 0x00002b2df126227c in QFileInfo::isDir (this=<value optimized out>) at io/qfileinfo.cpp:1059
  2. #1 0x00002b2df0040051 in QDirModel::isDir (this=<value optimized out>, index=@0x7fffbb797ff0)
  3. at itemviews/qdirmodel.cpp:941
To copy to clipboard, switch view to plain text mode 

Maybe I am currently a bit boneheaded, but what is the problem here? this=<value optimized out>? I somewhat expected that the indices might get invalid when I delete a file from the list, but I am testing for that. The pointers are ok, since the first file is successfully deleted. Any ideas?