Ensure QQuickView's engine outlives the root component
authorMatthew Vogt <matthew.vogt@nokia.com>
Wed, 23 May 2012 22:55:39 +0000 (08:55 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 23 May 2012 23:12:44 +0000 (01:12 +0200)
If the engine is destroyed before the root component, assumptions of
resource availability are broken.

Change-Id: I7fe27ff38ae3c215d58fb8811aff449b6c1f7b5b
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquickview.cpp

index b6b6f41..b3fba60 100644 (file)
@@ -81,8 +81,6 @@ QQuickViewPrivate::~QQuickViewPrivate()
 {
     if (QQmlDebugService::isDebuggingEnabled())
         QQmlInspectorService::instance()->removeView(q_func());
-
-    delete root;
 }
 
 void QQuickViewPrivate::execute()
@@ -215,6 +213,11 @@ QQuickView::QQuickView(QQmlEngine* engine, QWindow *parent, Qt::WindowFlags f)
 
 QQuickView::~QQuickView()
 {
+    // Ensure that the component is destroyed before the engine; the engine may
+    // be a child of the QQuickViewPrivate, and will be destroyed by its dtor
+    Q_D(QQuickView);
+    delete d->root;
+    d->root = 0;
 }
 
 /*! \property QQuickView::source