diff --git a/autotests/kmainwindow_unittest.h b/autotests/kmainwindow_unittest.h --- a/autotests/kmainwindow_unittest.h +++ b/autotests/kmainwindow_unittest.h @@ -37,6 +37,7 @@ void testAutoSaveSettings(); void testNoAutoSave(); void testWidgetWithStatusBar(); + void testNativeWidgetSaveSettings(); void testDeleteOnClose(); }; diff --git a/autotests/kmainwindow_unittest.cpp b/autotests/kmainwindow_unittest.cpp --- a/autotests/kmainwindow_unittest.cpp +++ b/autotests/kmainwindow_unittest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include QTEST_MAIN(KMainWindow_UnitTest) @@ -226,3 +227,71 @@ QStatusBar *frameStatusBar = new QStatusBar(frame1); QVERIFY(mw.statusBar() != frameStatusBar); } + + +class NativeMainWindow : public KMainWindow +{ +public: + NativeMainWindow() : KMainWindow() + { + m_dock = new QDockWidget(QStringLiteral("dock"), this); + m_dock->setObjectName(QStringLiteral("dock")); + m_dock->setAllowedAreas(Qt::AllDockWidgetAreas); + m_dock->setFeatures(QDockWidget::DockWidgetMovable); + m_dock->setFloating(false); + + QWidget *w = new QWidget(m_dock); + + m_dock->setWidget(w); + addDockWidget(Qt::RightDockWidgetArea, m_dock); + + setCentralWidget(new QWidget(this)); + + show(); + + setAutoSaveSettings(QStringLiteral("NativeWidgetTestGroup")); + + w->setAttribute(Qt::WA_NativeWindow); + } + + QDockWidget *m_dock; +}; + +void KMainWindow_UnitTest::testNativeWidgetSaveSettings() +{ + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, [&](QObject *){ el.exit(); }); // quit event loop when window's gone + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } + + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, [&](QObject *){ el.exit(); }); + + el.processEvents(); + QVERIFY(mw->m_dock->isVisible() == true); + mw->m_dock->hide(); + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } + + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, [&](QObject *){ el.exit(); }); + + QVERIFY(mw->m_dock->isVisible() == false); + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } +} diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp --- a/src/kmainwindow.cpp +++ b/src/kmainwindow.cpp @@ -524,6 +524,11 @@ } if (queryClose()) { + // widgets will start destroying themselves at this point and we don't + // want to save state anymore after this as it might be incorrect + d->autoSaveSettings = false; + d->letDirtySettings = false; + e->accept(); } else { e->ignore(); //if the window should not be closed, don't close it