aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmldata_p.h
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2012-04-03 12:37:29 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-03 16:22:04 +0200
commit7aa4c4164e0b7e09bfb0ea50d7f70203f7871bc6 (patch)
tree159697b3f94cb5cf591f46be4535253e9ad62ea3 /src/qml/qml/qqmldata_p.h
parent411066bdf2d09a8f0071eb9d494287a6a95639fb (diff)
Don't crash if calling a method on a QObject that has been gc()'d
As we don't actually delete an object immediately when it is collected, it is possible to get into a situation where a method is called on an object after the collector has marked it to be destroyed. This fixes a crash in this case. Change-Id: I131d4c5d7ed788a91aa52f6af2e5c089d9bf5e08 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmldata_p.h')
-rw-r--r--src/qml/qml/qqmldata_p.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h
index e7e001c4f2..3dd1c3ccba 100644
--- a/src/qml/qml/qqmldata_p.h
+++ b/src/qml/qml/qqmldata_p.h
@@ -181,11 +181,25 @@ public:
QQmlNotifier *objectNameNotifier() const;
QHash<int, QObject *> *attachedProperties() const;
+ static inline bool wasDeleted(QObject *);
private:
// For objectNameNotifier and attachedProperties
mutable QQmlDataExtended *extendedData;
};
+bool QQmlData::wasDeleted(QObject *object)
+{
+ if (!object)
+ return true;
+
+ QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
+ if (priv->wasDeleted)
+ return true;
+
+ return priv->declarativeData &&
+ static_cast<QQmlData *>(priv->declarativeData)->isQueuedForDeletion;
+}
+
QQmlNotifierEndpoint *QQmlData::notify(int index)
{
Q_ASSERT(index <= 0xFFFF);