Clean up objects in QQmlApplicationEngine earlier
authorAlan Alpert <aalpert@blackberry.com>
Tue, 30 Jul 2013 22:27:31 +0000 (15:27 -0700)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 31 Jul 2013 06:37:02 +0000 (08:37 +0200)
Deleting the objects in the private class destructor leads to
crashes in V8 because the JS engine is in the middle of being
deleted. Instead, delete the objects in the public class
destructor so that it occurs before the actual engine cleanup
starts to happen.

Change-Id: I6bac813ce188be54842a78d7b532fcf2d54dc444
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
src/qml/qml/qqmlapplicationengine.cpp
src/qml/qml/qqmlapplicationengine_p.h

index 9181dad..85aeaf5 100644 (file)
@@ -54,6 +54,10 @@ QQmlApplicationEnginePrivate::QQmlApplicationEnginePrivate(QQmlEngine *e)
 
 QQmlApplicationEnginePrivate::~QQmlApplicationEnginePrivate()
 {
+}
+
+void QQmlApplicationEnginePrivate::cleanUp()
+{
     qDeleteAll(objects);
 #ifndef QT_NO_TRANSLATIONS
     qDeleteAll(translators);
@@ -229,7 +233,8 @@ QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *p
 */
 QQmlApplicationEngine::~QQmlApplicationEngine()
 {
-    //Instantiated root objects cleaned up in private class
+    Q_D(QQmlApplicationEngine);
+    d->cleanUp();//Instantiated root objects must be deleted before the engine
 }
 
 /*!
index db144af..cc38c62 100644 (file)
@@ -70,6 +70,7 @@ public:
     QQmlApplicationEnginePrivate(QQmlEngine *e);
     ~QQmlApplicationEnginePrivate();
     void init();
+    void cleanUp();
 
     void startLoad(const QUrl &url, const QByteArray &data = QByteArray(), bool dataFlag = false);
     void loadTranslations(const QUrl &rootFile);