]> vaikene.ee Git - evaf/blobdiff - src/libs/Common/eventqueue.cpp
Replaced QPointer<> with QWeakPointer<>
[evaf] / src / libs / Common / eventqueue.cpp
index bbf30ed8ae2f12d1ff213ea6845f3517c8781a91..33e73c0d6e54e26888f3fd1e7651f3fe1435c5a8 100644 (file)
@@ -67,20 +67,20 @@ bool EventQueue::event(QEvent * e)
         }
 
         // 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
@@ -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<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)