Passing Data from QML to QML via Loader
-
Hello guy,
I search for that kind of topic but didn't find any good solution.
What I need is a way to pass data to let's say a qml screen file.
The qml has to take the passed data into account. For example
user rights etc.
How can I pass data to a qml file which is loaded via a Loader {} ?
If i set the properties of the qml Item the qml file is already processed
and i can't set the properties before loading or processing the qml file.What is the appropriate way to pass data to a qml file?
It seems that propertie-bindings will not work in that case. -
Yep I guess the way it works is to load the qml file first.
Then access the loader.item which is the loaded qml file
and set the properties of the Item.This is what I already tried but not in a consistent way.
For example:
@
property string main_text: "default"
property int screen_mode: 0Item { anchors.fill: parent visible: { if (screen_mode == 1) true else false }
@
If i use the propertie-bindings correctly it works pretty well.
In this way i can redefine the visibility after the qml file is processed.
That makes the propertie-bindings way more powerful than the approach I
was thinking of. -
You can pass initial property values as a parameter to Loader's setSource method. See http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-loader.html#setSource-method for more information.
Component can take a similar parameter to its createObject and incubateObject methods: https://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-component.html#createObject-method
Cheers,
Chris.