summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@nokia.com>2010-02-15 12:33:07 (GMT)
committerMorten Johan Sørvig <morten.sorvig@nokia.com>2010-02-23 12:37:10 (GMT)
commit526c6fd4686a8e87e5087ebcac941405f742304a (patch)
treecb16c07e1db7908e73019092705ca8543c19a566 /src/gui/kernel/qwidget.cpp
parentde4332a4728e739b37e9c7b04c021e150e096270 (diff)
downloadQt-526c6fd4686a8e87e5087ebcac941405f742304a.zip
Qt-526c6fd4686a8e87e5087ebcac941405f742304a.tar.gz
Qt-526c6fd4686a8e87e5087ebcac941405f742304a.tar.bz2
Prevent stale QWidget pointers in QCocoaView
QCocoaView has two "back" pointers ot its owning QWidget and the corresponding QWidgetPrivate. The lifetime of the QCocoaView might be longer and that of the QWidget if Cocoa itself holds references to it. In addition accessing a QWidget that is being destroyed is not safe. Set both pack pointers to NULL in ~QWidget. This prevents following stale pointers in the QCocoaView callbacks. This also means that we'll see the NULL pointers, add gurads for that.
Diffstat (limited to 'src/gui/kernel/qwidget.cpp')
-rw-r--r--src/gui/kernel/qwidget.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index d433048..1e9b1d9 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -1468,6 +1468,15 @@ QWidget::~QWidget()
d->declarativeData = 0; // don't activate again in ~QObject
}
+#ifdef QT_MAC_USE_COCOA
+ // QCocoaView holds a pointer back to this widget. Clear it now
+ // to make sure it's not followed later on. The lifetime of the
+ // QCocoaView might exceed the lifetime of this widget in cases
+ // where Cocoa itself holds references to it.
+ extern void qt_mac_clearCocoaViewQWidgetPointers(QWidget *);
+ qt_mac_clearCocoaViewQWidgetPointers(this);
+#endif
+
if (!d->children.isEmpty())
d->deleteChildren();