aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2024-02-29 10:13:08 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2024-02-29 17:56:20 +0100
commit1ebd8ef8535466f4d0059ad7b38682407c91d96a (patch)
treea33504feb202d1ec47fefef7dde7eca80e432f91 /examples/quick
parent98ecc9adbbb0f032f4ef4341d4cdd896158d4409 (diff)
quickwidget example: Avoid potential for crash on close
Widgets that had been broken out to separate top-level windows would live on after the mainwindow was closed. Subsequent attempts to move them back to the tab widget would crash, since the that would be deleted by then. Fix by closing detached top-level windows on mainwindow close. Fixes: QTBUG-122790 Pick-to: 6.7 6.6 6.5 Change-Id: I0ae268c5e30b6563dc1556b3f79a83418cc3c703 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp
index 584cecfb00..f8e0b78844 100644
--- a/examples/quick/quickwidgets/quickwidget/main.cpp
+++ b/examples/quick/quickwidgets/quickwidget/main.cpp
@@ -112,10 +112,12 @@ void MainWindow::createQuickWidgetsInTabs(QMdiArea *mdiArea)
if (widget->parent()) {
widget->setAttribute(Qt::WA_DeleteOnClose, true);
widget->setParent(nullptr);
+ connect(this, &QObject::destroyed, widget, &QWidget::close);
widget->show();
btn->setText(msgFromTopLevel);
} else {
widget->setAttribute(Qt::WA_DeleteOnClose, false);
+ disconnect(this, &QObject::destroyed, widget, &QWidget::close);
tabWidget->addTab(widget, widget->windowTitle());
btn->setText(msgToTopLevel);
}
@@ -201,8 +203,9 @@ int main(int argc, char **argv)
optMultipleSample = parser.isSet(multipleSampleOption);
- MainWindow mainWindow;
- mainWindow.show();
+ MainWindow *mainWindow = new MainWindow;
+ mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
+ mainWindow->show();
return app.exec();
}