aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlworkerscript/qquickworkerscript.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-01-03 18:22:26 +0100
committerUlf Hermann <ulf.hermann@qt.io>2025-01-08 17:27:15 +0100
commit4d03da9da398b66e8dcf2c63280d5d8f4de1ef20 (patch)
treeda95987cd30a4dc92604082fda52fc80416e9482 /src/qmlworkerscript/qquickworkerscript.cpp
parent3a862c4d5ab627071d47266849ad8184ff2ef7f6 (diff)
QtQml: Move network access manager factory into type loader
It's used from both, the type loader and the engine thread, and also from worker scripts. Add a comment to explain why it needs a separate mutex. Task-number: QTBUG-131721 Change-Id: I12ec2fe462349b3ad5f34262d3f43dfa78f0487f Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qmlworkerscript/qquickworkerscript.cpp')
-rw-r--r--src/qmlworkerscript/qquickworkerscript.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp
index dc19b3a119..219cd4a394 100644
--- a/src/qmlworkerscript/qquickworkerscript.cpp
+++ b/src/qmlworkerscript/qquickworkerscript.cpp
@@ -112,9 +112,12 @@ public:
WorkerDestroyEvent = QEvent::User + 100
};
- QQuickWorkerScriptEnginePrivate(QQmlEngine *eng);
+ QQuickWorkerScriptEnginePrivate(QQmlTypeLoader *typeLoader)
+ : m_typeLoader(typeLoader), m_nextId(0)
+ {
+ }
- QQmlEngine *qmlengine;
+ QQmlTypeLoader *m_typeLoader = nullptr;
QMutex m_lock;
QWaitCondition m_wait;
@@ -125,7 +128,7 @@ public:
// the worker script.
QHash<int, QBiPointer<QV4::ExecutionEngine, QQuickWorkerScript>> workers;
- int m_nextId;
+ int m_nextId = 0;
static QV4::ReturnedValue method_sendMessage(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
QV4::ExecutionEngine *workerEngine(int id);
@@ -142,11 +145,6 @@ private:
void reportScriptException(WorkerScript *, const QQmlError &error);
};
-QQuickWorkerScriptEnginePrivate::QQuickWorkerScriptEnginePrivate(QQmlEngine *engine)
-: qmlengine(engine), m_nextId(0)
-{
-}
-
QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(const QV4::FunctionObject *b,
const QV4::Value *, const QV4::Value *argv, int argc)
{
@@ -342,7 +340,8 @@ QQmlError WorkerErrorEvent::error() const
}
QQuickWorkerScriptEngine::QQuickWorkerScriptEngine(QQmlEngine *parent)
-: QThread(parent), d(new QQuickWorkerScriptEnginePrivate(parent))
+ : QThread(parent)
+ , d(new QQuickWorkerScriptEnginePrivate(&QQmlEnginePrivate::get(parent)->typeLoader))
{
d->m_lock.lock();
connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection);
@@ -390,12 +389,10 @@ WorkerScript::WorkerScript(QV4::ExecutionEngine *engine)
#if QT_CONFIG(qml_network)
engine->networkAccessManager = [](QV4::ExecutionEngine *engine) {
WorkerScript *workerScript = workerScriptExtension(engine);
- if (workerScript->scriptLocalNAM)
- return workerScript->scriptLocalNAM.get();
- if (auto *namFactory = workerScript->p->qmlengine->networkAccessManagerFactory())
- workerScript->scriptLocalNAM.reset(namFactory->create(workerScript->p));
- else
- workerScript->scriptLocalNAM.reset(new QNetworkAccessManager(workerScript->p));
+ if (!workerScript->scriptLocalNAM) {
+ workerScript->scriptLocalNAM.reset(
+ workerScript->p->m_typeLoader->createNetworkAccessManager(workerScript->p));
+ }
return workerScript->scriptLocalNAM.get();
};
#endif // qml_network