aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2015-06-17 16:38:47 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-23 17:31:51 +0000
commit1b4f94c8fe0452cc053907fea2ad8be3930df8ce (patch)
tree3c65361cdeb08ce764979b8e35604f4a84c8f909 /src
parentfcbefee383ccff2a6485acc120631123e30b41dd (diff)
Force completion of asynchronously loaded components.
[ChangeLog][QtQuick][QQmlComponent] Synchronously complete the loading of a Asynchronous QQmlComponent, if a PreferSynchronous QQmlComponent is created for the same url (given that this url does support synchronous loading). Change-Id: I3291d0569a69bac2aeb4815f1068a426ef2707ef Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/ftw/qqmlthread.cpp27
-rw-r--r--src/qml/qml/ftw/qqmlthread_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp14
3 files changed, 43 insertions, 0 deletions
diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp
index 4addcd9e58..62f6f76a7e 100644
--- a/src/qml/qml/ftw/qqmlthread.cpp
+++ b/src/qml/qml/ftw/qqmlthread.cpp
@@ -377,4 +377,31 @@ void QQmlThread::internalPostMethodToMain(Message *message)
d->unlock();
}
+void QQmlThread::waitForNextMessage()
+{
+ Q_ASSERT(!isThisThread());
+ d->lock();
+ Q_ASSERT(d->m_mainThreadWaiting == false);
+
+ d->m_mainThreadWaiting = true;
+
+ if (d->mainSync || !d->threadList.isEmpty()) {
+ if (d->mainSync) {
+ QQmlThread::Message *message = d->mainSync;
+ unlock();
+ message->call(this);
+ delete message;
+ lock();
+ d->mainSync = 0;
+ wakeOne();
+ } else {
+ d->wait();
+ }
+ }
+
+ d->m_mainThreadWaiting = false;
+ d->unlock();
+}
+
+
QT_END_NAMESPACE
diff --git a/src/qml/qml/ftw/qqmlthread_p.h b/src/qml/qml/ftw/qqmlthread_p.h
index 86d7d2cf19..73658536ac 100644
--- a/src/qml/qml/ftw/qqmlthread_p.h
+++ b/src/qml/qml/ftw/qqmlthread_p.h
@@ -108,6 +108,8 @@ public:
template<typename T, typename T2, class V, class V2, class O>
inline void postMethodToMain(void (O::*Member)(V, V2), const T &, const T2 &);
+ void waitForNextMessage();
+
protected:
virtual void startupThread();
virtual void shutdownThread();
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index e860b8e0fa..408f17ffde 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -1612,6 +1612,20 @@ QQmlTypeData *QQmlTypeLoader::getType(const QUrl &url, Mode mode)
} else {
QQmlTypeLoader::load(typeData, mode);
}
+ } else if ((mode == PreferSynchronous) && QQmlFile::isSynchronous(url)) {
+ // this was started Asynchronous, but we need to force Synchronous
+ // completion now (if at all possible with this type of URL).
+
+ if (!m_thread->isThisThread()) {
+ // this only works when called directly from the UI thread, but not
+ // when recursively called on the QML thread via resolveTypes()
+
+ while (!typeData->isCompleteOrError()) {
+ unlock();
+ m_thread->waitForNextMessage();
+ lock();
+ }
+ }
}
typeData->addref();