"some Js Files Act More Like Libraries - They [...] Never Manipulate Qml Component Instances Directly" - Middle Ground?
Solution 1:
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.
Solution 2:
To share data across qml files, consider using a qml Singleton.
For data sharing purpose, I would not suggest using .pragma library
(@Mitch) for following reasons.
.pragma library
js provides limited functionality in qml object manipulation. While simple qml object manipulation (like property reading/writing) could be done with a.pragma library
js, it does NOT allow creating/deleting qml objects (as you can in regular non-library js). It will suck when your application becomes dynamic..pragma library
creating only one instance is merely an optimization in Qt implementation. It's never guaranteed that Qt creates exactly one instance, nor that your data would actually be shared.Well,
.pragma library
is not designed to do data sharing work from the very beginning. Just, don't try to do it this way.
Post a Comment for ""some Js Files Act More Like Libraries - They [...] Never Manipulate Qml Component Instances Directly" - Middle Ground?"