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.
  • Stefan Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on 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
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on 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

      Stefan Monov76S 1 Reply Last reply
      0
      • JKSHJ JKSH

        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?

        Stefan Monov76S Offline
        Stefan Monov76S Offline
        Stefan Monov76
        wrote on 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
        • Stefan Monov76S Offline
          Stefan Monov76S Offline
          Stefan Monov76
          wrote on last edited by
          #4

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

          JKSHJ 1 Reply Last reply
          1
          • Stefan Monov76S Stefan Monov76

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

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on 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

            • Login

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