From 0b70d8c6afb525d80cf4f1fc788e1a5947f0b152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 14 Mar 2012 12:16:45 +0100 Subject: [PATCH] Improved qWaitForWindowShown(). Made faster by actually waiting for the window to be exposed, using similar waiting logic as qWait(). Should speed up autotests that use it quite a bit. Change-Id: I628c6110a554fdbbf5bed7e91f57c2fe341113ed Reviewed-by: Lars Knoll --- src/testlib/qtestsystem.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index 1f10967557..ade5f4c8ac 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -53,9 +53,6 @@ QT_BEGIN_NAMESPACE class QWidget; -#ifdef Q_WS_X11 -extern void qt_x11_wait_for_window_manager(QWidget *w); -#endif namespace QTest { @@ -73,23 +70,26 @@ namespace QTest } inline static bool qWaitForWindowShown(QWidget *window) - { -#if defined(Q_WS_X11) - qt_x11_wait_for_window_manager(window); - QCoreApplication::processEvents(); -#else - Q_UNUSED(window); - qWait(200); -#endif - return true; - } - inline static bool qWaitForWindowShown(QWindow *window) { Q_UNUSED(window); qWait(200); return true; } + inline static bool qWaitForWindowShown(QWindow *window) + { + QElapsedTimer timer; + timer.start(); + while (!window->isExposed()) { + int remaining = int(timer.elapsed()) - 1000; + if (remaining <= 0) + break; + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QTest::qSleep(10); + } + return true; + } } QT_END_NAMESPACE