diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-31 15:35:34 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-03 11:18:13 (GMT) |
commit | 128717b171f01c82e5f0fb83f5923d4f7b9cfc10 (patch) | |
tree | 5e138ede4db646436a3af071247546f820e42ed8 | |
parent | 1b469ac64cf81476436009aef66009c30335a01c (diff) | |
download | Qt-128717b171f01c82e5f0fb83f5923d4f7b9cfc10.zip Qt-128717b171f01c82e5f0fb83f5923d4f7b9cfc10.tar.gz Qt-128717b171f01c82e5f0fb83f5923d4f7b9cfc10.tar.bz2 |
Remove currentChildBeingDeleted from QObjectPrivate.
When a child is being deleted by its parent, the child should not
notify the parent (of that which it already knows anyway). We did that
by keeping a pointer to the child being deleted. Much simpler to
simply orphan the child.
Reviewed-by: Bradley T. Hughes
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 29 | ||||
-rw-r--r-- | src/corelib/kernel/qobject_p.h | 5 |
2 files changed, 13 insertions, 21 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index ab91799..7bf209a 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -123,7 +123,7 @@ extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *) } QObjectPrivate::QObjectPrivate(int version) - : threadData(0), currentSender(0), currentChildBeingDeleted(0), connectionLists(0), senders(0) + : threadData(0), currentSender(0), declarativeData(0), connectionLists(0), senders(0) { if (version != QObjectPrivateVersion) qFatal("Cannot mix incompatible Qt libraries"); @@ -1859,12 +1859,13 @@ void QObjectPrivate::deleteChildren() // don't use qDeleteAll as the destructor of the child might // delete siblings for (int i = 0; i < children.count(); ++i) { - currentChildBeingDeleted = children.at(i); + QObject *child = children.at(i); children[i] = 0; - delete currentChildBeingDeleted; + if (child) + child->d_func()->parent = 0; + delete child; } children.clear(); - currentChildBeingDeleted = 0; wasDeleted = reallyWasDeleted; } @@ -1875,20 +1876,14 @@ void QObjectPrivate::setParent_helper(QObject *o) return; if (parent) { QObjectPrivate *parentD = parent->d_func(); - if (parentD->wasDeleted && wasDeleted - && parentD->currentChildBeingDeleted == q) { - // don't do anything since QObjectPrivate::deleteChildren() already - // cleared our entry in parentD->children. + const int index = parentD->children.indexOf(q); + if (parentD->wasDeleted) { + parentD->children[index] = 0; } else { - const int index = parentD->children.indexOf(q); - if (parentD->wasDeleted) { - parentD->children[index] = 0; - } else { - parentD->children.removeAt(index); - if (sendChildEvents && parentD->receiveChildEvents) { - QChildEvent e(QEvent::ChildRemoved, q); - QCoreApplication::sendEvent(parent, &e); - } + parentD->children.removeAt(index); + if (sendChildEvents && parentD->receiveChildEvents) { + QChildEvent e(QEvent::ChildRemoved, q); + QCoreApplication::sendEvent(parent, &e); } } } diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index e908753..0b41c9a 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -125,10 +125,7 @@ public: // object currently activating the object Sender *currentSender; - union { - QObject *currentChildBeingDeleted; - QDeclarativeData *declarativeData; - }; + QDeclarativeData *declarativeData; bool isSender(const QObject *receiver, const char *signal) const; QObjectList receiverList(const char *signal) const; |