From 99aefbb4c00ce2ad01bea186a297a3407b1da973 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 10 Aug 2020 16:23:36 +0200 Subject: QFileDialog: fix warning message when navigating to "My Computer" The mapping between model indexes, QUrl, and QDir in QFileDialog resulted in QFileSystemEngine methods being called on empty strings, which results in a warning from QFileSystemEngine. When QFileDialog gets an empty string as the new path, then we know that it's the "My Computer" location, so handle that case separately. This makes sure we don't call any QFileSystemEngine methods with an empty string. Change-Id: I421d3d76b053379c216c41a72fb783d1bad176cb Pick-to: 5.15 Fixes: QTBUG-67866 Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qfiledialog.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index e81fc66a03..0a39217b99 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1891,9 +1891,11 @@ void QFileDialogComboBox::setHistory(const QStringList &paths) m_history = paths; // Only populate the first item, showPopup will populate the rest if needed QList list; - QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); + const QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); //On windows the popup display the "C:\", convert to nativeSeparators - QUrl url = QUrl::fromLocalFile(QDir::toNativeSeparators(idx.data(QFileSystemModel::FilePathRole).toString())); + const QUrl url = idx.isValid() + ? QUrl::fromLocalFile(QDir::toNativeSeparators(idx.data(QFileSystemModel::FilePathRole).toString())) + : QUrl(QLatin1String("file:")); if (url.isValid()) list.append(url); urlModel->setUrls(list); @@ -3351,8 +3353,7 @@ void QFileDialogPrivate::saveHistorySelection() void QFileDialogPrivate::_q_pathChanged(const QString &newPath) { Q_Q(QFileDialog); - QDir dir(model->rootDirectory()); - qFileDialogUi->toParentButton->setEnabled(dir.exists()); + qFileDialogUi->toParentButton->setEnabled(QFileInfo::exists(model->rootPath())); qFileDialogUi->sidebar->selectUrl(QUrl::fromLocalFile(newPath)); q->setHistory(qFileDialogUi->lookInCombo->history()); -- cgit v1.2.3