From 2b0f2c1c8452c16723a15f00117c96c57bb017a8 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Thu, 17 Sep 2009 10:49:33 +0200 Subject: Added a QTest::qWaitForWindowShown function that waits for window manager on X11. On X11 it calls the qt_x11_wait_for_window_manager from QtGui, allowing to wait until the window has been mapped and reparented into a frame decoration parent. Reviewed-by: Olivier Goffart --- doc/src/snippets/code/src_qtestlib_qtestcase.cpp | 6 ++++++ src/testlib/qtestcase.cpp | 10 ++++++++++ src/testlib/qtestsystem.h | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/doc/src/snippets/code/src_qtestlib_qtestcase.cpp index bf2a897..951dfbb 100644 --- a/doc/src/snippets/code/src_qtestlib_qtestcase.cpp +++ b/doc/src/snippets/code/src_qtestlib_qtestcase.cpp @@ -225,5 +225,11 @@ void MyTestClass::cleanup() QTest::qSleep(250); //! [23] +//! [24] +QWidget widget; +widget.show(); +QTest::qWaitForWindowShown(&widget); +//! [24] + } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 74c3af9..96f8a1b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -731,6 +731,16 @@ QT_BEGIN_NAMESPACE \sa QTest::qSleep() */ +/*! \fn void QTest::qWaitForWindowManager(QWidget *window) + + Waits until the window is shown in the screen. This is mainly useful for + asynchronous systems like X11, where a window will be mapped to screen some + time after being asked to show itself on the screen. + + Example: + \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 24 +*/ + /*! \class QTest::QTouchEventSequence \inmodule QtTest diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index bdcc826..540b18d 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -52,6 +52,11 @@ QT_BEGIN_NAMESPACE QT_MODULE(Test) +class QWidget; +#ifdef Q_WS_X11 +extern void qt_x11_wait_for_window_manager(QWidget *w); +#endif + namespace QTest { inline static void qWait(int ms) @@ -65,6 +70,19 @@ namespace QTest QTest::qSleep(10); } while (timer.elapsed() < ms); } + + inline static bool qWaitForWindowShown(QWidget *window) + { +#if defined(Q_WS_X11) + qt_x11_wait_for_window_manager(window); +#elif defined(Q_WS_QWS) + qWait(100); +#else + qWait(50); +#endif + return true; + } + } QT_END_NAMESPACE -- cgit v0.12