summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2018-03-22 17:34:16 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2018-03-27 15:08:46 +0000
commitcdbd68fc2fab60fdf6834615db586715b01f4380 (patch)
tree5af85c1a29d8b83c0bf0e001a6fbb1bb340a8dcc /src/corelib
parent09f3b19f989d83e01bd53f512b928550ee81ec2c (diff)
Allow QWinEventNotifier to coexist with waiting functions
Many subclasses of QIODevice have a functionality to block execution until some asynchronous I/O operation completes. In case we are using QWinEventNotifier, a typical reimplemented waitFor{ReadyRead |BytesWritten}() function could look like: if (WaitForSingleObject(notifier.handle(),...) == WAIT_OBJECT_0) { notifier.setEnabled(false); ResetEvent(notifier.handle()); bool res = GetOverlappedResult(...); ... return true; } Despite the fact that the operation ends synchronously, it leaves the notifier in a state that indicates it has received the event, so its next call to setEnabled(true) will produce a fake notification. So, we should reset a notifier's history before enabling it again. Change-Id: I62a9dd809ce6a7a40e9d8038f2a49299b36f8142 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qwineventnotifier.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/kernel/qwineventnotifier.cpp b/src/corelib/kernel/qwineventnotifier.cpp
index 24de491326..85d4ad4fa9 100644
--- a/src/corelib/kernel/qwineventnotifier.cpp
+++ b/src/corelib/kernel/qwineventnotifier.cpp
@@ -157,7 +157,6 @@ void QWinEventNotifier::setHandle(HANDLE hEvent)
Q_D(QWinEventNotifier);
setEnabled(false);
d->handleToEvent = hEvent;
- d->signaledCount = 0;
}
/*!
@@ -209,10 +208,12 @@ void QWinEventNotifier::setEnabled(bool enable)
return;
}
- if (enable)
+ if (enable) {
+ d->signaledCount = 0;
eventDispatcher->registerEventNotifier(this);
- else
+ } else {
eventDispatcher->unregisterEventNotifier(this);
+ }
}
/*!