summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-05 09:26:34 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-05 13:16:28 (GMT)
commitd1150c5bbf6be125d496ce71570140ea28836ba5 (patch)
tree2f79bfe2d555d68468cb3d9e56be06f716e6bcbc /src/corelib/kernel
parent520cfa6b6cf4b53a02cc08f01323da036d5b9bea (diff)
downloadQt-d1150c5bbf6be125d496ce71570140ea28836ba5.zip
Qt-d1150c5bbf6be125d496ce71570140ea28836ba5.tar.gz
Qt-d1150c5bbf6be125d496ce71570140ea28836ba5.tar.bz2
Restore symmetry between QSharedPointer and QWeakPointer on QObjects.
With the previous commit, you could create a QWeakPointer from any QObject-derived object. It's possible because QObject now has a pointer to the QWeakPointer's d-pointer. However, if you did: QSharedPointer<QObject> obj(new QObject); QWeakPointer<QObject> weak1(obj); QWeakPointer<QObject> weak2(obj.data()); Then weak1 would shared d-pointers with QSharedPointer, but weak2 wouldn't. Also, weak1.toStrongRef() would work, but weak2.toStrongRef() wouldn't. This change makes QObject know where the d-pointer created by QSharedPointer is, so weak2 would get the same d-pointer. As a nice side-effect, you can check if a given QObject is shared by trying to promote its QWeakPointer to QSharedPointer. Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qobject.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 3417232..e37b6d3 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -770,6 +770,11 @@ QObject::~QObject()
}
if (d->sharedRefcount) {
+ if (d->sharedRefcount->strongref > 0) {
+ qWarning("QObject: shared QObject was deleted directly. The program is malformed and may crash.");
+ // but continue deleting, it's too late to stop anyway
+ }
+
// indicate to all QWeakPointers that this QObject has now been deleted
d->sharedRefcount->strongref = 0;
if (!d->sharedRefcount->weakref.deref())