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 9ff40b59da

Pick-to: 6.6 6.5
Change-Id: I2c3bdc1eb06731d9c38979610303876c2748fb73
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Mårten Nordheim 2023-11-06 14:57:30 +01:00
parent c524ca342b
commit 26ded9dedf
1 changed files with 3 additions and 2 deletions

View File

@ -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<QDockWidget> d1;
QPointer<QDockWidget> d2;
QPointer<QWidget> 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();