X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Feventqueue.cpp;h=795224c8fbc42022801da892670789897e54b59f;hb=60aebc188674bbfb67be51958ec33171c72986b9;hp=bbf30ed8ae2f12d1ff213ea6845f3517c8781a91;hpb=5815060246f84e8efdf3143b4e8c7d00778168cf;p=evaf
diff --git a/src/libs/Common/eventqueue.cpp b/src/libs/Common/eventqueue.cpp
index bbf30ed..795224c 100644
--- a/src/libs/Common/eventqueue.cpp
+++ b/src/libs/Common/eventqueue.cpp
@@ -45,6 +45,7 @@ EventQueue::EventQueue()
: iEventQueue()
, mNextEventId(1)
{
+ iRegistry::instance()->registerInterface("iEventQueue", this);
}
EventQueue::~EventQueue()
@@ -67,20 +68,20 @@ bool EventQueue::event(QEvent * e)
}
// Send the event to all the subscribers
- QHash > >::const_iterator subscribersIt = mSubscribers.constFind(id);
+ QHash > >::const_iterator subscribersIt = mSubscribers.constFind(id);
if (subscribersIt != mSubscribers.constEnd()) {
- QList > subscribers = *subscribersIt;
+ QVector > 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 obj = subscribers.at(i);
+ QWeakPointer 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
@@ -146,7 +147,15 @@ void EventQueue::unsubscribeEvent(uint id, QObject * obj)
if (mEvents.constFind(id) == mEvents.constEnd())
return;
- mSubscribers[id].removeAll(obj);
+ // Remove from the list of subscribers
+ QVector >::iterator it = mSubscribers[id].begin();
+ QVector >::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)