javascriptqtqmlqtquick2sailfish-os

How to import javascript file to qml worker script


I'm creating an application in me where I want to download data from the internet. To avoid blocking of main thread I created a WorkerScript file. This works fine, but I need to abstract certain parts (like authorization, proper header, etc) to general-purpose functions.

Unfortunately, I haven't found a way to import the js file to the js file that serves as a worker thread. ".import" causes syntax error.

How can I achieve this?

Thank you.

Edit:

This is the relevant part from qml file:

Page {
    WorkerScript {
          id: myWorker
          source: Qt.resolvedUrl("loadDetails.js")
          onMessage:  {}
      }
}

And this is loadDetails.js:

.import "jsonrpc.js" as Jrpc
WorkerScript.onMessage = function(message) {
    // This is where I want to call functions from included file
}

Solution

  • See documentation provided by Oleg:

    Worker script can not use .import syntax.