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 9 Jul 2015, 10:54 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?

    P 1 Reply Last reply 9 Jul 2015, 11:05
    0
    • S sk2212
      9 Jul 2015, 10:54

      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?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 9 Jul 2015, 11:05 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 9 Jul 2015, 11:18
      0
      • P p3c0
        9 Jul 2015, 11:05

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

        S Offline
        S Offline
        sk2212
        wrote on 9 Jul 2015, 11:18 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?

        P 1 Reply Last reply 9 Jul 2015, 11:23
        0
        • S sk2212
          9 Jul 2015, 11:18

          @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?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 9 Jul 2015, 11:23 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

          1/4

          9 Jul 2015, 10:54

          • Login

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