From ed5bc72f76f0bd246f6f70b5be1aeec18b06f261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 6 Nov 2023 14:57:30 +0100 Subject: [PATCH] tst_QDockWidget: use local context for timer If we use 'this' as context it might still try to invoke the timer after we have left the function, leading to stack-use-after-return. To avoid doing an in-depth dive if it's okay to use mainWindow as the context or not, I just added a new local QObject. Amends 9ff40b59da58160dc26c54204a615a2456e07405 Pick-to: 6.5 Change-Id: I2c3bdc1eb06731d9c38979610303876c2748fb73 Reviewed-by: Volker Hilsheimer (cherry picked from commit 26ded9dedf3f35e93b81bd0281fdd0bd30acb9d4) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 5b46a4880a4..64615173a2b 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -1529,6 +1529,7 @@ void tst_QDockWidget::closeAndDelete() QSKIP("Test skipped on Wayland."); #ifdef QT_BUILD_INTERNAL // Create a mainwindow with a central widget and two dock widgets + QObject localContext; QPointer d1; QPointer d2; QPointer cent; @@ -1555,7 +1556,7 @@ void tst_QDockWidget::closeAndDelete() // Close everything with a single shot. Expected behavior: Event loop stops bool eventLoopStopped = true; - QTimer::singleShot(0, this, [mainWindow, d1, d2] { + QTimer::singleShot(0, &localContext, [mainWindow, d1, d2] { mainWindow->close(); QTRY_VERIFY(!mainWindow->isVisible()); QTRY_VERIFY(d1->isVisible()); @@ -1567,7 +1568,7 @@ void tst_QDockWidget::closeAndDelete() }); // Fallback timer to report event loop still running - QTimer::singleShot(100, this, [&eventLoopStopped] { + QTimer::singleShot(100, &localContext, [&eventLoopStopped] { qCDebug(lcTestDockWidget) << "Last dock widget hasn't shout down event loop!"; eventLoopStopped = false; QApplication::quit();