summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qfiledialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs/qfiledialog.cpp')
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index b638adeaec..97afce1734 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -3417,7 +3417,7 @@ void QFileDialogPrivate::_q_deleteCurrent()
QModelIndexList list = qFileDialogUi->listView->selectionModel()->selectedRows();
for (int i = list.count() - 1; i >= 0; --i) {
- QModelIndex index = list.at(i);
+ QPersistentModelIndex index = list.at(i);
if (index == qFileDialogUi->listView->rootIndex())
continue;
@@ -3427,7 +3427,6 @@ void QFileDialogPrivate::_q_deleteCurrent()
QString fileName = index.data(QFileSystemModel::FileNameRole).toString();
QString filePath = index.data(QFileSystemModel::FilePathRole).toString();
- bool isDir = model->isDir(index);
QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt());
#if QT_CONFIG(messagebox)
@@ -3443,13 +3442,16 @@ void QFileDialogPrivate::_q_deleteCurrent()
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
return;
+ // the event loop has run, we have to validate if the index is valid because the model might have removed it.
+ if (!index.isValid())
+ return;
+
#else
if (!(p & QFile::WriteUser))
return;
#endif // QT_CONFIG(messagebox)
- // the event loop has run, we can NOT reuse index because the model might have removed it.
- if (isDir) {
+ if (model->isDir(index) && !model->fileInfo(index).isSymLink()) {
if (!removeDirectory(filePath)) {
#if QT_CONFIG(messagebox)
QMessageBox::warning(q, q->windowTitle(),