diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-06-03 14:35:29 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-06-17 07:00:33 +0200 |
| commit | d2bc4a4330254c0c68a0ade51b59a71c4b67b470 (patch) | |
| tree | 8345312f50df0be783618fd75a1d7e52c2ca65d7 /src/qmlworkerscript/qquickworkerscript.cpp | |
| parent | 8e0810c19c791386fd5f2cefc6b992f45be21750 (diff) | |
QtQml: Hold QQmlTypeLoader in QV4::ExecutionEngine
... rather than QQmlEngine. This paves the way for having the type
loader attached to ExecutionEngine rather than QQmlEngine.
Also, reference the execution engine in the type loader, in turn.
Task-number: QTBUG-19407
Change-Id: I04e571c5c6ac5bce5e82537cb96c6940c7186f3a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlworkerscript/qquickworkerscript.cpp')
| -rw-r--r-- | src/qmlworkerscript/qquickworkerscript.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index dbb8281a99..14cd783c32 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -105,7 +105,11 @@ public: WorkerDestroyEvent() : QEvent(QEvent::Type(WorkerEventType::Destroy)) {} }; -struct WorkerScript : public QV4::ExecutionEngine::Deletable +struct WorkerScript + : public QV4::ExecutionEngine::Deletable +#if QT_CONFIG(qml_network) + , public QQmlNetworkAccessManagerFactory +#endif { WorkerScript(QV4::ExecutionEngine *); ~WorkerScript() = default; @@ -113,7 +117,7 @@ struct WorkerScript : public QV4::ExecutionEngine::Deletable QQuickWorkerScriptEnginePrivate *p = nullptr; QQuickWorkerScript *owner = nullptr; #if QT_CONFIG(qml_network) - QScopedPointer<QNetworkAccessManager> scriptLocalNAM; + QNetworkAccessManager *create(QObject *parent) final; #endif }; @@ -222,6 +226,10 @@ QV4::ExecutionEngine *QQuickWorkerScriptEnginePrivate::workerEngine(int id) WorkerScript *script = workerScriptExtension(engine); script->owner = owner; script->p = this; +#if QT_CONFIG(qml_network) + // Eagerly create a network access manager that can outlive the parent engine. + engine->getNetworkAccessManager(); +#endif *it = engine; return engine; } @@ -305,7 +313,7 @@ void QQuickWorkerScriptEnginePrivate::reportScriptException(WorkerScript *script QQuickWorkerScriptEngine::QQuickWorkerScriptEngine(QQmlEngine *parent) : QThread(parent) - , d(new QQuickWorkerScriptEnginePrivate(&QQmlEnginePrivate::get(parent)->typeLoader)) + , d(new QQuickWorkerScriptEnginePrivate(QQmlTypeLoader::get(parent))) { connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection); QMutexLocker locker(&d->m_lock); @@ -348,17 +356,17 @@ WorkerScript::WorkerScript(QV4::ExecutionEngine *engine) engine->globalObject->put(workerScriptName, api); #if QT_CONFIG(qml_network) - engine->networkAccessManager = [](QV4::ExecutionEngine *engine) { - WorkerScript *workerScript = workerScriptExtension(engine); - if (!workerScript->scriptLocalNAM) { - workerScript->scriptLocalNAM.reset( - workerScript->p->m_typeLoader->createNetworkAccessManager(workerScript->p)); - } - return workerScript->scriptLocalNAM.get(); - }; + engine->typeLoader()->setNetworkAccessManagerFactory(this); #endif // qml_network } +#if QT_CONFIG(qml_network) +QNetworkAccessManager *WorkerScript::create(QObject *parent) +{ + return p->m_typeLoader->createNetworkAccessManager(parent); +} +#endif + int QQuickWorkerScriptEngine::registerWorkerScript(QQuickWorkerScript *owner) { const int id = d->m_nextId++; |
