1
votes

I should set property stringa1 and stringa2 on Test.qml item when I load the component through Loader qml (setSource):

Page1.qml

import QtQuick 2.7

Page1Form {

    button1.onClicked: {
        console.log("Button Pressed. Entered text: " + textField1.text);
        itemLoader.setSource("Test.qml", {"stringa1": "ScrivoStr1"}, {"stringa2": "ScrivoStr2"})
    }

    itemToFill.children:
        Loader {
            anchors.fill: parent
            id: itemLoader
        }
}

Test.qml

import QtQuick 2.4

TestForm {

    property string stringa1
    property string stringa2

    signal setStr1(string str1)

    anchors.fill: parent

    Component.onCompleted: {

        button.text = stringa1 + " - " + stringa2

    }

    button.onClicked: console.log("Push");

}

When I set stringa1 and stringa2 with the following command:

itemLoader.setSource("Test.qml", {"stringa1": "ScrivoStr1"}, {"stringa2": "ScrivoStr2"})

Test.qml read only stringa1 value.

Which is the best way to set/transfer parameters between Qml Loader component and Item loaded? Thanks in advice

Best Regards Daniele

1

1 Answers

1
votes

It should be:

itemLoader.setSource("Test.qml", {"stringa1": "ScrivoStr1", "stringa2": "ScrivoStr2"})

Note that setSource is declared as:

object setSource(url source, object properties)

It accepts only one object that contains all the properties. You were passing multiple objects instead. Only the first one is taken in consideration in your case, all the others are discarded.
If you have to use multiple parameters, put all of them in a single object. That's all.