OSDN Git Service

QDeclarativeDebug: Fix when client with ongoing queries is deleted
authorKai Koehne <kai.koehne@nokia.com>
Thu, 24 Mar 2011 08:30:06 +0000 (09:30 +0100)
committerKai Koehne <kai.koehne@nokia.com>
Thu, 24 Mar 2011 08:46:42 +0000 (09:46 +0100)
Will also be fixed in QtDeclarative / 4.8.

Reviewed-by: Christiaan Janssen
src/libs/qmljsdebugclient/qdeclarativedebug.cpp

index 64ae390..7da7beb 100644 (file)
@@ -82,6 +82,7 @@ public:
     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *);
     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *);
     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *);
+    static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugWatch *);
 
     QHash<int, QDeclarativeDebugEnginesQuery *> enginesQuery;
     QHash<int, QDeclarativeDebugRootContextQuery *> rootContextQuery;
@@ -122,6 +123,41 @@ QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate()
 {
     if (client)
         client->priv = 0;
+     delete client;
+
+     QHash<int, QDeclarativeDebugEnginesQuery*>::iterator enginesIter = enginesQuery.begin();
+     for (; enginesIter != enginesQuery.end(); ++enginesIter) {
+         enginesIter.value()->m_client = 0;
+         if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting)
+             enginesIter.value()->setState(QDeclarativeDebugQuery::Error);
+     }
+
+     QHash<int, QDeclarativeDebugRootContextQuery*>::iterator rootContextIter = rootContextQuery.begin();
+     for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) {
+         rootContextIter.value()->m_client = 0;
+         if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting)
+             rootContextIter.value()->setState(QDeclarativeDebugQuery::Error);
+     }
+
+     QHash<int, QDeclarativeDebugObjectQuery*>::iterator objectIter = objectQuery.begin();
+     for (; objectIter != objectQuery.end(); ++objectIter) {
+         objectIter.value()->m_client = 0;
+         if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting)
+             objectIter.value()->setState(QDeclarativeDebugQuery::Error);
+     }
+
+     QHash<int, QDeclarativeDebugExpressionQuery*>::iterator exprIter = expressionQuery.begin();
+     for (; exprIter != expressionQuery.end(); ++exprIter) {
+         exprIter.value()->m_client = 0;
+         if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting)
+             exprIter.value()->setState(QDeclarativeDebugQuery::Error);
+     }
+
+     QHash<int, QDeclarativeDebugWatch*>::iterator watchIter = watched.begin();
+     for (; watchIter != watched.end(); ++watchIter) {
+         watchIter.value()->m_client = 0;
+         watchIter.value()->setState(QDeclarativeDebugWatch::Dead);
+     }
 }
 
 int QDeclarativeEngineDebugPrivate::getId()
@@ -146,6 +182,14 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
     }
 }
 
+void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugWatch *w)
+{
+    if (c && w) {
+        QDeclarativeEngineDebugPrivate *p = c->d_func();
+        p->watched.remove(w->m_queryId);
+    }
+}
+
 // from qdeclarativeenginedebug_p.h
 struct QDeclarativeObjectData {
     QUrl url;
@@ -689,6 +733,8 @@ QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent)
 
 QDeclarativeDebugWatch::~QDeclarativeDebugWatch()
 {
+    if (m_client && m_queryId != -1)
+        QDeclarativeEngineDebugPrivate::remove(m_client, this);
 }
 
 int QDeclarativeDebugWatch::queryId() const