diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 9219757dbf..e53cdeac29 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -454,15 +454,15 @@ QByteArray QFileDialog::saveState() const stream << d->qFileDialogUi->splitter->saveState(); stream << d->qFileDialogUi->sidebar->urls(); } else { - stream << QByteArray(); - stream << QList(); + stream << d->splitterState; + stream << d->sidebarUrls; } stream << history(); stream << *lastVisitedDir(); if (d->usingWidgets()) stream << d->qFileDialogUi->treeView->header()->saveState(); else - stream << QByteArray(); + stream << d->headerData; stream << qint32(viewMode()); return data; } @@ -484,9 +484,6 @@ bool QFileDialog::restoreState(const QByteArray &state) QDataStream stream(&sd, QIODevice::ReadOnly); if (stream.atEnd()) return false; - QByteArray splitterState; - QByteArray headerData; - QList bookmarks; QStringList history; QString currentDirectory; qint32 marker; @@ -497,11 +494,11 @@ bool QFileDialog::restoreState(const QByteArray &state) if (marker != QFileDialogMagic || v != version) return false; - stream >> splitterState - >> bookmarks + stream >> d->splitterState + >> d->sidebarUrls >> history >> currentDirectory - >> headerData + >> d->headerData >> viewMode; setDirectory(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir()); @@ -510,7 +507,7 @@ bool QFileDialog::restoreState(const QByteArray &state) if (!d->usingWidgets()) return true; - if (!d->qFileDialogUi->splitter->restoreState(splitterState)) + if (!d->qFileDialogUi->splitter->restoreState(d->splitterState)) return false; QList list = d->qFileDialogUi->splitter->sizes(); if (list.count() >= 2 && list.at(0) == 0 && list.at(1) == 0) { @@ -519,12 +516,12 @@ bool QFileDialog::restoreState(const QByteArray &state) d->qFileDialogUi->splitter->setSizes(list); } - d->qFileDialogUi->sidebar->setUrls(bookmarks); + d->qFileDialogUi->sidebar->setUrls(d->sidebarUrls); while (history.count() > 5) history.pop_front(); setHistory(history); QHeaderView *headerView = d->qFileDialogUi->treeView->header(); - if (!headerView->restoreState(headerData)) + if (!headerView->restoreState(d->headerData)) return false; QList actions = headerView->actions(); diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h index 632bbca5a4..89c6414b71 100644 --- a/src/widgets/dialogs/qfiledialog_p.h +++ b/src/widgets/dialogs/qfiledialog_p.h @@ -273,6 +273,11 @@ public: QSharedPointer options; + // Memory of what was read from QSettings in restoreState() in case widgets are not used + QByteArray splitterState; + QByteArray headerData; + QList sidebarUrls; + ~QFileDialogPrivate(); private: