From c7fb7a678251a6fc090d851b897f67d561b66625 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Fri, 16 Mar 2012 15:09:18 +1000 Subject: Fix broken qWaitForWindowShown() behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qWaitForWindowShown() should check window->isActive() instead of window->isExposed() and return false if timeout. Add two new qWaitForWindowActive() and qWaitForWindowExposed() functions. Change-Id: Idd9601805c2e84b0d36ddd5471031b627d289953 Reviewed-by: Samuel Rødal --- src/testlib/qtestsystem.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/testlib/qtestsystem.h') diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index ade5f4c8ac..095f791cac 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -76,19 +76,39 @@ namespace QTest return true; } - inline static bool qWaitForWindowShown(QWindow *window) + inline static bool qWaitForWindowActive(QWindow *window, int timeout = 1000) + { + QElapsedTimer timer; + timer.start(); + while (!window->isActive()) { + int remaining = timeout - int(timer.elapsed()); + if (remaining <= 0) + break; + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QTest::qSleep(10); + } + return window->isActive(); + } + + inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 1000) { QElapsedTimer timer; timer.start(); while (!window->isExposed()) { - int remaining = int(timer.elapsed()) - 1000; + int remaining = timeout - int(timer.elapsed()); if (remaining <= 0) break; QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QTest::qSleep(10); } - return true; + return window->isExposed(); + } + + inline static bool qWaitForWindowShown(QWindow *window, int timeout = 1000) + { + return qWaitForWindowActive(window, timeout); } } -- cgit v1.2.3