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); + } } /*! diff --git a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp index 76efa008f7..74beab96a6 100644 --- a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp +++ b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp @@ -46,6 +46,7 @@ protected slots: private slots: void simple_data(); void simple(); + void blockedWaiting(); void manyNotifiers(); void disableNotifiersInActivatedSlot_data(); void disableNotifiersInActivatedSlot(); @@ -104,6 +105,26 @@ void tst_QWinEventNotifier::simple() QVERIFY(simpleActivated); } +void tst_QWinEventNotifier::blockedWaiting() +{ + simpleHEvent = CreateEvent(0, true, false, 0); + QWinEventNotifier n(simpleHEvent); + QObject::connect(&n, &QWinEventNotifier::activated, + this, &tst_QWinEventNotifier::simple_activated); + simpleActivated = false; + + SetEvent(simpleHEvent); + QCOMPARE(WaitForSingleObject(simpleHEvent, 1000), WAIT_OBJECT_0); + + n.setEnabled(false); + ResetEvent(simpleHEvent); + n.setEnabled(true); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(QTestEventLoop::instance().timeout()); + QVERIFY(!simpleActivated); +} + class EventWithNotifier : public QObject { Q_OBJECT