From 7e5452a23f02c87f73f729cf6eab0ffe1ffa440c Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 30 Oct 2013 15:14:16 +0100 Subject: [PATCH] Fix QFileDialog::getSaveFilename() with a given default name The QFileDialogOptions::initiallySelectedFiles were overridden, and the given filename was also not properly converted to a local file URL. Task-number: QTBUG-34408 Task-number: QTBUG-34446 Change-Id: I51d05b954a5393d10db9232945ba05bda7068e73 Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qfiledialog.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 22d467661e..cfdc303f21 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -628,7 +628,8 @@ void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) QUrl::fromLocalFile(directory.absolutePath()) : QUrl()); options->setInitiallySelectedNameFilter(q->selectedNameFilter()); - options->setInitiallySelectedFiles(userSelectedFiles()); + if (options->initiallySelectedFiles().isEmpty()) + options->setInitiallySelectedFiles(userSelectedFiles()); } void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) @@ -1053,10 +1054,13 @@ void QFileDialog::selectFile(const QString &filename) return; if (!d->usingWidgets()) { - d->selectFile_sys(QUrl::fromLocalFile(filename)); - QList i; - i << QUrl(filename); - d->options->setInitiallySelectedFiles(i); + QUrl url = QUrl::fromLocalFile(filename); + if (QFileInfo(filename).isRelative()) { + QDir dir(d->options->initialDirectory().toLocalFile()); + url = QUrl::fromLocalFile(dir.absoluteFilePath(filename)); + } + d->selectFile_sys(url); + d->options->setInitiallySelectedFiles(QList() << url); return; } @@ -1683,11 +1687,8 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) d->options->setAcceptMode(static_cast(mode)); // clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly setAttribute(Qt::WA_DontShowOnScreen, false); - if (!d->usingWidgets()) { - // we need to recreate the native dialog when changing the AcceptMode - d->deletePlatformHelper(); + if (!d->usingWidgets()) return; - } QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save); d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel); d->qFileDialogUi->buttonBox->button(button)->setEnabled(false);