Fix QSplashScreen on X11.

Use code from QTestLib to wait for the Window to show up.

Change-Id: Ib674f3eb7a6c32cad1d502caefe7d4b073754e73
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
This commit is contained in:
Friedemann Kleint 2012-07-16 12:22:04 +02:00 committed by Qt by Nokia
parent 59096732f6
commit 117b27dc8d

View File

@ -49,9 +49,17 @@
#include "qpixmap.h"
#include "qtextdocument.h"
#include "qtextcursor.h"
#include <QtGui/qwindow.h>
#include <QtCore/qdebug.h>
#include <QtCore/qelapsedtimer.h>
#include <private/qwidget_p.h>
#ifdef Q_OS_WIN
# include <QtCore/qt_windows.h>
#else
# include <time.h>
#endif
QT_BEGIN_NAMESPACE
class QSplashScreenPrivate : public QWidgetPrivate
@ -217,18 +225,37 @@ void QSplashScreen::clearMessage()
repaint();
}
// A copy of QTestLib's qWaitForWindowExposed() and qSleep().
inline static bool waitForWindowExposed(QWindow *window, int timeout = 1000)
{
enum { TimeOutMs = 10 };
QElapsedTimer timer;
timer.start();
while (!window->isExposed()) {
const int remaining = timeout - int(timer.elapsed());
if (remaining <= 0)
break;
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
#ifdef Q_OS_WIN
Sleep(uint(TimeOutMs));
#else
struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 };
nanosleep(&ts, NULL);
#endif
}
return window->isExposed();
}
/*!
Makes the splash screen wait until the widget \a mainWin is displayed
before calling close() on itself.
*/
void QSplashScreen::finish(QWidget *mainWin)
{
if (mainWin) {
#if defined(Q_WS_X11)
extern void qt_x11_wait_for_window_manager(QWidget *mainWin, bool);
qt_x11_wait_for_window_manager(mainWin, false);
#endif
}
if (mainWin && mainWin->windowHandle())
waitForWindowExposed(mainWin->windowHandle());
close();
}