: iEventQueue()
, mNextEventId(1)
{
+ iRegistry::instance()->registerInterface("iEventQueue", this);
}
EventQueue::~EventQueue()
}
// Send the event to all the subscribers
- QHash<uint, QList<QPointer<QObject> > >::const_iterator subscribersIt = mSubscribers.constFind(id);
+ QHash<uint, QVector<QWeakPointer<QObject> > >::const_iterator subscribersIt = mSubscribers.constFind(id);
if (subscribersIt != mSubscribers.constEnd()) {
- QList<QPointer<QObject> > subscribers = *subscribersIt;
+ QVector<QWeakPointer<QObject> > subscribers = *subscribersIt;
int sz = subscribers.size();
for (int i = 0; i < sz; ++i) {
// Get the subscriber object and make sure that it is still alive
- QPointer<QObject> obj = subscribers.at(i);
+ QWeakPointer<QObject> obj = subscribers.at(i);
if (obj.isNull()) {
continue;
}
// Notify the subscriber
- bool rval = QCoreApplication::sendEvent(obj, e);
+ bool rval = QCoreApplication::sendEvent(obj.data(), e);
if (rval) {
// The event was consumed and should be sent to any other subscribers
if (mEvents.constFind(id) == mEvents.constEnd())
return;
- mSubscribers[id].removeAll(obj);
+ // Remove from the list of subscribers
+ QVector<QWeakPointer<QObject> >::iterator it = mSubscribers[id].begin();
+ QVector<QWeakPointer<QObject> >::iterator e = mSubscribers[id].end();
+ while (it != e) {
+ if (!it->isNull() && it->data() == obj)
+ it = mSubscribers[id].erase(it);
+ else
+ ++it;
+ }
}
void EventQueue::broadcastEvent(Event * event)