aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlworkerscript
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2019-12-06 10:56:22 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-12-06 14:32:16 +0000
commit3c4247e1e021b6bcc480afc0716e0231575d0501 (patch)
tree8f1f72b91e150b88e53e5b4ccac6a551e096220b /src/qmlworkerscript
parent8fadf5d374936e50b8bce5adb1f10da2f66eac2b (diff)
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 <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlworkerscript')
-rw-r--r--src/qmlworkerscript/qquickworkerscript.cpp13
-rw-r--r--src/qmlworkerscript/qquickworkerscript_p.h5
2 files changed, 18 insertions, 0 deletions
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
@@ -533,6 +533,17 @@ void QQuickWorkerScript::setSource(const QUrl &source)
}
/*!
+ \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)
Sends the given \a message to a worker script handler in another
@@ -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;
diff --git a/src/qmlworkerscript/qquickworkerscript_p.h b/src/qmlworkerscript/qquickworkerscript_p.h
index 9b5d3587fb..d1f686a78d 100644
--- a/src/qmlworkerscript/qquickworkerscript_p.h
+++ b/src/qmlworkerscript/qquickworkerscript_p.h
@@ -87,6 +87,8 @@ class Q_AUTOTEST_EXPORT QQuickWorkerScript : public QObject, public QQmlParserSt
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(bool ready READ ready NOTIFY readyChanged)
+
QML_NAMED_ELEMENT(WorkerScript);
Q_INTERFACES(QQmlParserStatus)
@@ -97,11 +99,14 @@ public:
QUrl source() const;
void setSource(const QUrl &);
+ bool ready() const;
+
public Q_SLOTS:
void sendMessage(QQmlV4Function*);
Q_SIGNALS:
void sourceChanged();
+ void readyChanged();
void message(const QJSValue &messageObject);
protected: