I have a QDirModel in a QDirTree. I select several files in this view and try to delete them with with following routine:
foreach
(QModelIndex index,selectionModel
()->selectedIndexes
()){ if(index.isValid() && index.column()==0){
if(dirModel->isReadOnly()){
return;
}
// Crashes here the second time.
if(dirModel->isDir(index)){
dirModel->rmdir(index);
}else{
dirModel->remove(index);
}
}
}
foreach(QModelIndex index,selectionModel()->selectedIndexes()){
if(index.isValid() && index.column()==0){
if(dirModel->isReadOnly()){
return;
}
// Crashes here the second time.
if(dirModel->isDir(index)){
dirModel->rmdir(index);
}else{
dirModel->remove(index);
}
}
}
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:
#0 0x00002b2df126227c in QFileInfo::isDir (this=<value optimized out>) at io/qfileinfo.cpp:1059
#1 0x00002b2df0040051 in QDirModel::isDir (this=<value optimized out>, index=@0x7fffbb797ff0)
at itemviews/qdirmodel.cpp:941
#0 0x00002b2df126227c in QFileInfo::isDir (this=<value optimized out>) at io/qfileinfo.cpp:1059
#1 0x00002b2df0040051 in QDirModel::isDir (this=<value optimized out>, index=@0x7fffbb797ff0)
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?
Bookmarks