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. "Some JS files act more like libraries - they [...] never manipulate QML component instances directly" - middle ground?

"Some JS files act more like libraries - they [...] never manipulate QML component instances directly" - middle ground?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
javascript qml
5 Posts 2 Posters 1.7k Views
  • 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
    Stefan Monov76
    wrote on 14 Sept 2016, 18:24 last edited by Stefan Monov76
    #1

    Quote from Defining JavaScript Resources In QML:

    Some JavaScript files act more like libraries - they provide a set of helper functions that take input and compute output, but never manipulate QML component instances directly.

    What if I want a JS file that both:

    • manipulates QML component instances (that are passed to it as arguments)
    • doesn't get a copy of its code and data stored for every QML component instance that imports it?

    I could get the "no data stored on every instance" part by, well, not putting global variables in the JS file. But, for some strange reason, a copy of the "code" part seems to be stored for every instance as well. I don't get why this is but I want to know whether I can circumvent it, and at what cost.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 15 Sept 2016, 08:34 last edited by
      #2

      Hi @Stefan-Monov76, and welcome to the Qt Dev Net!

      I'm not very familiar with this part of QML, but I'll see what I can do.

      I could get the "no data stored on every instance" part by, well, not putting global variables in the JS file.

      Remember to use .pragma library too.

      But, for some strange reason, a copy of the "code" part seems to be stored for every instance as well.

      How did you find out that a copy has been stored with every instance?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      S 1 Reply Last reply 15 Sept 2016, 16:35
      0
      • J JKSH
        15 Sept 2016, 08:34

        Hi @Stefan-Monov76, and welcome to the Qt Dev Net!

        I'm not very familiar with this part of QML, but I'll see what I can do.

        I could get the "no data stored on every instance" part by, well, not putting global variables in the JS file.

        Remember to use .pragma library too.

        But, for some strange reason, a copy of the "code" part seems to be stored for every instance as well.

        How did you find out that a copy has been stored with every instance?

        S Offline
        S Offline
        Stefan Monov76
        wrote on 15 Sept 2016, 16:35 last edited by
        #3

        @JKSH said in "Some JS files act more like libraries - they [...] never manipulate QML component instances directly" - middle ground?:

        Hi @Stefan-Monov76, and welcome to the Qt Dev Net!

        Hi! I'm not that new here though :)

        Remember to use .pragma library too.

        Sure, the quote in the title is from the "library-like JS" section (not the "code-behind JS" section) of the doc page, and this does require using .pragma library. So I know about that. The problem is that then in this JS resource I "cannot manipulate QML component instances directly", not even if they're passed to me as an argument (that's what the quote stated). Which is a strange limitation.

        How did you find out that a copy has been stored with every instance?

        Well, the doc page I linked to in my original post says this right next:

        "As it would be wasteful for each QML component instance to have a unique copy of these libraries [...]"

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Stefan Monov76
          wrote on 15 Sept 2016, 17:03 last edited by
          #4

          Update: I got a working solution on StackOverflow, you can see it here :)

          J 1 Reply Last reply 15 Sept 2016, 23:35
          1
          • S Stefan Monov76
            15 Sept 2016, 17:03

            Update: I got a working solution on StackOverflow, you can see it here :)

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 15 Sept 2016, 23:35 last edited by
            #5

            @Stefan-Monov76 said in "Some JS files act more like libraries - they [...] never manipulate QML component instances directly" - middle ground?:

            Update: I got a working solution on StackOverflow, you can see it here :)

            Thanks for sharing, and for reporting the doc issue :)

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0

            1/5

            14 Sept 2016, 18:24

            • Login

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