From 7aa4c4164e0b7e09bfb0ea50d7f70203f7871bc6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Apr 2012 12:37:29 +0100 Subject: 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 --- src/qml/qml/qqmldata_p.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/qml/qml/qqmldata_p.h') 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 *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(object)); + if (priv->wasDeleted) + return true; + + return priv->declarativeData && + static_cast(priv->declarativeData)->isQueuedForDeletion; +} + QQmlNotifierEndpoint *QQmlData::notify(int index) { Q_ASSERT(index <= 0xFFFF); -- cgit v1.2.3