Add a virtual sendPostedEvents() to QEventDispatcherWin32.

Reimplement this in QWindowGuiEventDispatcher to send both Qt posted events and
queued QPA window system events. We need to do this at a well defined place,
instead of sending events outside of the eventloop from the Windows proc.

This fixes various hangs for example in tst_qinputdialog, which used a 0-timer
to close a dialog.

Change-Id: I64e0b8f1209fb434059a7fa667ed585902c19db4
Initial-patch-by: bhughes <bradley.hughes@nokia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Friedemann Kleint 2012-01-20 08:57:17 +01:00 committed by Qt by Nokia
parent c274ea7cf5
commit 0f8ad242fb
5 changed files with 19 additions and 11 deletions

View File

@ -408,7 +408,7 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
const int localSerialNumber = d->serialNumber.load();
if (localSerialNumber != d->lastSerialNumber) {
d->lastSerialNumber = localSerialNumber;
QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
q->sendPostedEvents();
}
return 0;
} else if (message == WM_TIMER) {
@ -761,7 +761,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
if (!seenWM_QT_SENDPOSTEDEVENTS && (flags & QEventLoop::EventLoopExec) == 0) {
// when called "manually", always send posted events
QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
sendPostedEvents();
}
if (needWM_QT_SENDPOSTEDEVENTS)
@ -1076,4 +1076,10 @@ bool QEventDispatcherWin32::event(QEvent *e)
return QAbstractEventDispatcher::event(e);
}
void QEventDispatcherWin32::sendPostedEvents()
{
Q_D(QEventDispatcherWin32);
QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
}
QT_END_NAMESPACE

View File

@ -104,6 +104,7 @@ public:
protected:
QEventDispatcherWin32(QEventDispatcherWin32Private &dd, QObject *parent = 0);
virtual void sendPostedEvents();
private:
friend LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp);

View File

@ -747,18 +747,11 @@ extern "C" LRESULT QT_WIN_CALLBACK qWindowsWndProc(HWND hwnd, UINT message, WPAR
LRESULT result;
const QtWindows::WindowsEventType et = windowsEventType(message, wParam);
const bool handled = QWindowsContext::instance()->windowsProc(hwnd, message, et, wParam, lParam, &result);
const bool guiEventsQueued = QWindowSystemInterface::windowSystemEventsQueued();
if (QWindowsContext::verboseEvents > 1)
if (const char *eventName = QWindowsGuiEventDispatcher::windowsMessageName(message))
qDebug("EVENT: hwd=%p %s msg=0x%x et=0x%x wp=%d at %d,%d handled=%d gui=%d",
qDebug("EVENT: hwd=%p %s msg=0x%x et=0x%x wp=%d at %d,%d handled=%d",
hwnd, eventName, message, et, int(wParam),
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), handled, guiEventsQueued);
if (guiEventsQueued) {
const QWindowsGuiEventDispatcher::DispatchContext dispatchContext =
QWindowsGuiEventDispatcher::currentDispatchContext();
if (dispatchContext.first)
QWindowSystemInterface::sendWindowSystemEvents(dispatchContext.first, dispatchContext.second);
}
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), handled);
if (!handled)
result = DefWindowProc(hwnd, message, wParam, lParam);
return result;

View File

@ -97,6 +97,13 @@ bool QWindowsGuiEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags fl
return rc;
}
void QWindowsGuiEventDispatcher::sendPostedEvents()
{
QWindowsGuiEventDispatcher::DispatchContext context = currentDispatchContext();
Q_ASSERT(context.first != 0);
QWindowSystemInterface::sendWindowSystemEvents(context.first, context.second);
}
QWindowsGuiEventDispatcher::DispatchContext QWindowsGuiEventDispatcher::currentDispatchContext()
{
const DispatchContextStack &stack = *dispatchContextStack();

View File

@ -64,6 +64,7 @@ public:
static const char *windowsMessageName(UINT msg);
virtual bool QT_ENSURE_STACK_ALIGNED_FOR_SSE processEvents(QEventLoop::ProcessEventsFlags flags);
virtual void sendPostedEvents();
};
QT_END_NAMESPACE