From 3c4247e1e021b6bcc480afc0716e0231575d0501 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Fri, 6 Dec 2019 10:56:22 +0100 Subject: src/qmlworkerscript: Add ready property to WorkerScript Previously it was impossible to determine whether a WorkerScript has been fully initialized. This commit introduces a ready property that allows outside Components to determine whether it is safe to send signals. Fixes: QTBUG-80413 Change-Id: I2a1892b5e759e317de791e71d79fbb0cbd320dd3 Reviewed-by: Ulf Hermann --- src/qmlworkerscript/qquickworkerscript.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/qmlworkerscript/qquickworkerscript.cpp') diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index 8b236697b9..9e4b3e1b46 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -532,6 +532,17 @@ void QQuickWorkerScript::setSource(const QUrl &source) emit sourceChanged(); } +/*! + \qmlproperty url WorkerScript::ready + + This holds whether the WorkerScript has been initialized and is ready + for receiving messages via \tt WorkerScript.sendMessage(). +*/ +bool QQuickWorkerScript::ready() const +{ + return m_engine != nullptr; +} + /*! \qmlmethod WorkerScript::sendMessage(jsobject message) @@ -592,6 +603,8 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine() if (m_source.isValid()) m_engine->executeUrl(m_scriptId, m_source); + emit readyChanged(); + return m_engine; } return nullptr; -- cgit v1.2.3