diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-08-10 16:23:36 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-08-12 23:06:36 +0200 |
commit | 99aefbb4c00ce2ad01bea186a297a3407b1da973 (patch) | |
tree | dc5d774567c70c177428592d03dff85455b67c12 /src | |
parent | 5382bf4220bb76055943678196a84387510ee059 (diff) |
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 <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 9 |
1 files 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<QUrl> 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()); |