Passing data between QML. A QML <-> B QML
-
Hi everyone,
I am a beginner in QML. I am alone and ask for help.
Load B QML dynamically from A QML.
This is what you asked before.
Couldn't solve it.[A QML]
Loader { id: testButton source: "qrc:/B.qml" x: 100; y: 100 width: 200 height: 100 }
[B QML]
Rectangle { id: bQml property alias upData1: "aaaa" property alias upData2: "bbbb" property alias upData3: "cccc"
"A QML" loaded "B QML".
How can I change the values of upData1, upData2, upData3 of "B QML" in "A QML"?Please help.
-
Hi. You can access the inner properties using the item of Loader. Example: testButton.item.upData1 or testButton.item.upData2 or testButton.item.upData3.
Loader { id: testButton source: "qrc:/B.qml" x: 100; y: 100 width: 200 height: 100 testButton.item.upData1 : "aaa" }
If you do the above, you will get an error.
"Invalid property name "testButton". (M16)
Please give an exact example.
I need it so much. -
Loader { id: testButton source: "qrc:/B.qml" x: 100; y: 100 width: 200 height: 100 onLoaded: { item.upData1 = ...; item.upData2 = ...; } }
Other way, you can fill initial properties using setSource function - https://doc.qt.io/qt-5/qml-qtquick-loader.html#setSource-method
Loader { id: testButton x: 100; y: 100 width: 200 height: 100 Component.onCompleted: { setSource("qrc:/B.qml", { "upData1": "abc", "upData2": "bca", "upData3": Qt.binding(() => ... // if you need binding }); } } }
-
Loader { id: testButton source: "qrc:/B.qml" x: 100; y: 100 width: 200 height: 100 onLoaded: { item.upData1 = ...; item.upData2 = ...; } }
Other way, you can fill initial properties using setSource function - https://doc.qt.io/qt-5/qml-qtquick-loader.html#setSource-method
Loader { id: testButton x: 100; y: 100 width: 200 height: 100 Component.onCompleted: { setSource("qrc:/B.qml", { "upData1": "abc", "upData2": "bca", "upData3": Qt.binding(() => ... // if you need binding }); } } }