From 2a6a33767f7068fc5c43bc03f66df6329fc3cea6 Mon Sep 17 00:00:00 2001
From: Ulf Hermann <ulf.hermann@digia.com>
Date: Mon, 15 Sep 2014 16:57:35 +0200
Subject: [PATCH] Don't start QQmlThreads from their constructor

In the case of derived classes (like the only user of QQmlThread) we
cannot guarantee that the class is completely constructed when the
thread starts. This includes the vtable which is necessary to decide
which virtual functions to call.

Change-Id: Ieaea67a72cc3b4f845b8621b34ca2928185917fb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
---
 src/qml/qml/ftw/qqmlthread.cpp | 15 +++++++++------
 src/qml/qml/ftw/qqmlthread_p.h |  2 ++
 src/qml/qml/qqmltypeloader.cpp |  2 ++
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp
index 397b4851cf..18b257dc0e 100644
--- a/src/qml/qml/ftw/qqmlthread.cpp
+++ b/src/qml/qml/ftw/qqmlthread.cpp
@@ -207,12 +207,6 @@ void QQmlThreadPrivate::threadEvent()
 QQmlThread::QQmlThread()
 : d(new QQmlThreadPrivate(this))
 {
-    d->lock();
-    d->start();
-    d->wait();
-    d->unlock();
-    d->moveToThread(d);
-
 }
 
 QQmlThread::~QQmlThread()
@@ -220,6 +214,15 @@ QQmlThread::~QQmlThread()
     delete d;
 }
 
+void QQmlThread::startup()
+{
+    d->lock();
+    d->start();
+    d->wait();
+    d->unlock();
+    d->moveToThread(d);
+}
+
 void QQmlThread::shutdown()
 {
     d->lock();
diff --git a/src/qml/qml/ftw/qqmlthread_p.h b/src/qml/qml/ftw/qqmlthread_p.h
index 995fcd4824..95d32d4fd2 100644
--- a/src/qml/qml/ftw/qqmlthread_p.h
+++ b/src/qml/qml/ftw/qqmlthread_p.h
@@ -60,6 +60,8 @@ class QQmlThread
 public:
     QQmlThread();
     virtual ~QQmlThread();
+
+    void startup();
     void shutdown();
     bool isShutdown() const;
 
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 0b7cc8e911..0e2d4d027a 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -728,6 +728,8 @@ void QQmlDataBlob::ThreadData::setProgress(quint8 v)
 QQmlDataLoaderThread::QQmlDataLoaderThread(QQmlDataLoader *loader)
 : m_loader(loader), m_networkAccessManager(0), m_networkReplyProxy(0)
 {
+    // Do that after initializing all the members.
+    startup();
 }
 
 QNetworkAccessManager *QQmlDataLoaderThread::networkAccessManager() const
-- 
GitLab