Stefan Monov Stefan Monov - 1 year ago 64
Javascript Question

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

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.

Answer Source

I think that the line you quoted from the documentation is incorrect, or at least very poorly worded; you can still have a JS file with .pragma library in it and manipulate QML objects that are passed in as arguments to its functions. The sentence was probably referring to the previous section.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download