X-Git-Url: https://vaikene.ee/gitweb/highlight.css?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Feventqueue.cpp;h=33e73c0d6e54e26888f3fd1e7651f3fe1435c5a8;hb=8e0779e2e5a9f947f79c28e2ff121f6ffdd78b3f;hp=bbf30ed8ae2f12d1ff213ea6845f3517c8781a91;hpb=7432726bf8e4fc75cf96d330380448edc593bb2e;p=evaf diff --git a/src/libs/Common/eventqueue.cpp b/src/libs/Common/eventqueue.cpp index bbf30ed..33e73c0 100644 --- a/src/libs/Common/eventqueue.cpp +++ b/src/libs/Common/eventqueue.cpp @@ -67,20 +67,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 +146,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)