Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Import JavaScript library into "WorkerScript"
Forum Updated to NodeBB v4.3 + New Features

Import JavaScript library into "WorkerScript"

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sk2212
    wrote on last edited by
    #1

    import "test.js" as TEST // Does not work
    .import "test.js" as TEST2 // Does also not work

    WorkerScript.onMessage = function(message) {

    [...]

    }

    How to import the library "test.js" into a JavaScript source file of a WorkerScript?

    p3c0P 1 Reply Last reply
    0
    • S sk2212

      import "test.js" as TEST // Does not work
      .import "test.js" as TEST2 // Does also not work

      WorkerScript.onMessage = function(message) {

      [...]

      }

      How to import the library "test.js" into a JavaScript source file of a WorkerScript?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @sk2212 To include Js in Js use Qt.include(). Eg: Qt.include("sample.js")

      157

      S 1 Reply Last reply
      0
      • p3c0P p3c0

        Hi @sk2212 To include Js in Js use Qt.include(). Eg: Qt.include("sample.js")

        S Offline
        S Offline
        sk2212
        wrote on last edited by
        #3

        @p3c0

        Hmmm...working so far. JavaScript functions in library "test.js" are useable.

        But it seems that another new instance of this library is created although the first line in "test.js" is ".pragma library". Therefore I cannot use this approach for saving a global setting.

        Well, if this is not solveable this way I will use "sendMessage()" within WorkerScript to trigger onMessage function which will call the JavaScript-function in "test.js" in another QML file where I can use "import" syntax.

        Maybe this is also a "cleaner" solution?

        p3c0P 1 Reply Last reply
        0
        • S sk2212

          @p3c0

          Hmmm...working so far. JavaScript functions in library "test.js" are useable.

          But it seems that another new instance of this library is created although the first line in "test.js" is ".pragma library". Therefore I cannot use this approach for saving a global setting.

          Well, if this is not solveable this way I will use "sendMessage()" within WorkerScript to trigger onMessage function which will call the JavaScript-function in "test.js" in another QML file where I can use "import" syntax.

          Maybe this is also a "cleaner" solution?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @sk2212

          But it seems that another new instance of this library is created although the first line in "test.js" is ".pragma library". Therefore I cannot use this approach for saving a global setting.

          Yes it ignores pragmas and imports. See including-a-javascript-resource-from-another-javascript-resource for more info.

          import will only work in QML so you can go with your solution.

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved