Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102025

QML WorkerScript supports only one thread

    XMLWordPrintable

Details

    • Linux/X11

    Description

      The QML WorkerScript type will always reuse one thread, namely the QQmlEnginePrivate::workerScriptEngine thread (from the main/gui thread), no matter how many times the type is instantiated. This seems to be by design, though I don't really understand why. Now, either the design is wrong after all, or the documentation needs to be updated to clearly state that. From reading the documentation at least I got the impression that there's one thread per WorkerScript instance.

      Here is a very quick and dirty hack that provides the behavior that I would expect: 

      --- a/src/qmlworkerscript/qquickworkerscript.cpp
      +++ b/src/qmlworkerscript/qquickworkerscript.cpp
      @@ -623,10 +623,7 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine()
                   return nullptr;
               }
       
      -        QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine);
      -        if (enginePrivate->workerScriptEngine == nullptr)
      -            enginePrivate->workerScriptEngine = new QQuickWorkerScriptEngine(engine);
      -        m_engine = qobject_cast<QQuickWorkerScriptEngine *>(enginePrivate->workerScriptEngine);
      +        m_engine = new QQuickWorkerScriptEngine(engine);
               Q_ASSERT(m_engine);
               m_scriptId = m_engine->registerWorkerScript(this);

       

      Attachments

        For Gerrit Dashboard: QTBUG-102025
        # Subject Branch Project Status CR V

        Activity

          People

            qtqmlteam Qt Qml Team User
            bweimer Bernd Weimer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change