summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r--src/corelib/kernel/qobject.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 1938012..0801418 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -126,7 +126,7 @@ QObjectData::~QObjectData() {}
QObjectDeletionNotification::~QObjectDeletionNotification() {}
QObjectPrivate::QObjectPrivate(int version)
- : threadData(0), connectionLists(0), senders(0), currentSender(0), deletionNotification(0), objectGuards(0)
+ : threadData(0), connectionLists(0), senders(0), currentSender(0), currentChildBeingDeleted(0), deletionNotification(0), objectGuards(0)
{
if (version != QObjectPrivateVersion)
qFatal("Cannot mix incompatible Qt libraries");
@@ -1855,13 +1855,12 @@ void QObjectPrivate::deleteChildren()
// don't use qDeleteAll as the destructor of the child might
// delete siblings
for (int i = 0; i < children.count(); ++i) {
- QObject *child = children.at(i);
+ currentChildBeingDeleted = children.at(i);
children[i] = 0;
- if (child)
- child->d_func()->parent = 0;
- delete child;
+ delete currentChildBeingDeleted;
}
children.clear();
+ currentChildBeingDeleted = 0;
wasDeleted = reallyWasDeleted;
}
@@ -1872,14 +1871,20 @@ void QObjectPrivate::setParent_helper(QObject *o)
return;
if (parent) {
QObjectPrivate *parentD = parent->d_func();
- const int index = parentD->children.indexOf(q);
- if (parentD->wasDeleted) {
- parentD->children[index] = 0;
+ if (parentD->wasDeleted && wasDeleted
+ && parentD->currentChildBeingDeleted == q) {
+ // don't do anything since QObjectPrivate::deleteChildren() already
+ // cleared our entry in parentD->children.
} else {
- parentD->children.removeAt(index);
- if (sendChildEvents && parentD->receiveChildEvents) {
- QChildEvent e(QEvent::ChildRemoved, q);
- QCoreApplication::sendEvent(parent, &e);
+ 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);
+ }
}
}
}