Make the event notification on Windows be mandatory in all dispatchers

This way, QWinEventNotifier will work on all Windows systems, not just
with the default event dispatcher. Other dispatchers (other than
QWin32EventDispatcher) are permitted, so the class should not abort just
because of that.

If a dispatcher really doesn't want to implement this, they need to
implement the virtuals to do nothing, possibly print a warning.

Change-Id: I2c132bcde95b9d5941c8906a0fcd2ad964087772
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Thiago Macieira 2012-04-03 10:36:32 -03:00 committed by Qt by Nokia
parent b45f0418e3
commit 2376a5c4e0
6 changed files with 36 additions and 5 deletions

View File

@ -53,6 +53,10 @@ QT_BEGIN_NAMESPACE
class QAbstractEventDispatcherPrivate;
class QSocketNotifier;
#ifdef Q_OS_WIN
class QWinEventNotifier;
#endif
class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject
{
Q_OBJECT
@ -95,6 +99,11 @@ public:
virtual int remainingTime(int timerId) = 0;
#ifdef Q_OS_WIN
virtual bool registerEventNotifier(QWinEventNotifier *notifier) = 0;
virtual void unregisterEventNotifier(QWinEventNotifier *notifier) = 0;
#endif
virtual void wakeUp() = 0;
virtual void interrupt() = 0;
virtual void flush() = 0;

View File

@ -134,10 +134,12 @@ QWinEventNotifier::QWinEventNotifier(HANDLE hEvent, QObject *parent)
: QObject(*new QWinEventNotifierPrivate(hEvent, false), parent)
{
Q_D(QWinEventNotifier);
QEventDispatcherWin32 *eventDispatcher = qobject_cast<QEventDispatcherWin32 *>(d->threadData->eventDispatcher);
Q_ASSERT_X(eventDispatcher, "QWinEventNotifier::QWinEventNotifier()",
"Cannot create a win event notifier without a QEventDispatcherWin32");
eventDispatcher->registerEventNotifier(this);
QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher;
if (!eventDispatcher) {
qWarning("QWinEventNotifier: Can only be used with threads started with QThread");
} else {
eventDispatcher->registerEventNotifier(this);
}
d->enabled = true;
}
@ -205,7 +207,7 @@ void QWinEventNotifier::setEnabled(bool enable)
return;
d->enabled = enable;
QEventDispatcherWin32 *eventDispatcher = qobject_cast<QEventDispatcherWin32 *>(d->threadData->eventDispatcher);
QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher;
if (!eventDispatcher) // perhaps application is shutting down
return;

View File

@ -622,6 +622,11 @@ public:
void interrupt() {}
void flush() {}
#ifdef Q_OS_WIN
bool registerEventNotifier(QWinEventNotifier *) { return false; }
void unregisterEventNotifier(QWinEventNotifier *) { }
#endif
bool visited;
};

View File

@ -1239,6 +1239,11 @@ public:
void interrupt() {}
void flush() {}
#ifdef Q_OS_WIN
bool registerEventNotifier(QWinEventNotifier *) { return false; }
void unregisterEventNotifier(QWinEventNotifier *) { }
#endif
bool visited;
};

View File

@ -64,6 +64,11 @@ public:
bool unregisterTimers(QObject*) { return false; }
int remainingTime(int) { return 0; }
void wakeUp() {}
#ifdef Q_OS_WIN
bool registerEventNotifier(QWinEventNotifier *) { return false; }
void unregisterEventNotifier(QWinEventNotifier *) { }
#endif
};
class tst_BenchlibEventCounter: public QObject

View File

@ -64,6 +64,11 @@ public:
bool unregisterTimers(QObject*) { return false; }
int remainingTime(int) { return 0; }
void wakeUp() {}
#ifdef Q_OS_WIN
bool registerEventNotifier(QWinEventNotifier *) { return false; }
void unregisterEventNotifier(QWinEventNotifier *) { }
#endif
};
class tst_BenchlibOptions: public QObject