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>
This commit is contained in:
Volker Hilsheimer 2020-08-10 16:23:36 +02:00
parent 5382bf4220
commit 99aefbb4c0

View File

@ -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());