From 7e4c2ac711c0b68133f06ab997a33f8bf7c4f734 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 28 Mar 2022 15:16:27 +0200 Subject: [PATCH] Query the QWindow in every test iteration in qWFWExposed(QWidget) Task-number: QTBUG-102030 Change-Id: Ic8aee76570a000709b480ffbe19335518e3f7a7e Reviewed-by: Allan Sandfeld Jensen --- src/widgets/kernel/qtestsupport_widgets.cpp | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/widgets/kernel/qtestsupport_widgets.cpp b/src/widgets/kernel/qtestsupport_widgets.cpp index acc69d098c..2dfe9efd3b 100644 --- a/src/widgets/kernel/qtestsupport_widgets.cpp +++ b/src/widgets/kernel/qtestsupport_widgets.cpp @@ -47,9 +47,24 @@ #include #include #include +#include +#include QT_BEGIN_NAMESPACE +template +static bool qWaitForWidgetWindow(FunctorWindowGetter windowGetter, FunctorPredicate predicate, int timeout) +{ + if (!windowGetter()) + return false; + + return QTest::qWaitFor([&]() { + if (QWindow *window = windowGetter()) + return predicate(window); + return false; + }, timeout); +} + /*! \since 5.0 @@ -61,9 +76,17 @@ QT_BEGIN_NAMESPACE */ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout) { - if (QWindow *window = widget->window()->windowHandle()) - return QTest::qWaitForWindowActive(window, timeout); - return false; + if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))) { + qWarning() << "qWaitForWindowActive was called on a platform that doesn't support window" + << "activation. This means there is an error in the test and it should either" + << "check for the WindowActivation platform capability before calling" + << "qWaitForWindowActivate, use qWaitForWindowExposed instead, or skip the test." + << "Falling back to qWaitForWindowExposed."; + return qWaitForWindowExposed(widget, timeout); + } + return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); }, + [&](QWindow *window) { return window->isActive(); }, + timeout); } /*! @@ -86,9 +109,9 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout) */ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout) { - if (QWindow *window = widget->window()->windowHandle()) - return QTest::qWaitForWindowExposed(window, timeout); - return false; + return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); }, + [&](QWindow *window) { return window->isExposed(); }, + timeout); } namespace QTest {