2
votes

Main goal: have a context property that is set by a item defined into a QML file (say file_1.qml), and which will be accessed at runtime by other item defined in a different QML file (say file_2.qml).

Question: Is it possible to set a new context property in file_1.qml and then read this property in file_2.qml?

(edit)

For example, I would need to use a value from file_2.qml in file_1.qml:

file_1.qml:

(...)
UiController.but_generate__onClicked(
   getContextProperty("sbx_money_quantity_value"),
   cal_daysoff.visibleMonth)
(...)

file_2.qml:

(...)
SpinBox {
        id: sbx_money_quantity
        objectName: "sbx_money_quantity"
        Layout.fillWidth: true
        minimumValue: 0
        maximumValue: 100000
        value: 20000


        onChanged: setContextProperty("sbx_money_quantity_value",value)
    }
(...)

Thanks!

1
Can you show sample code which describes the problem? - folibis
I added an example. Thanks - pedromateo

1 Answers

1
votes

You cannot access an item in some file from another one due to scope limitation. So you just need some proxy root object or may be some global singleton object or just to pass reference to one object to another one. For example:

File1.qml

Item {   
    property someValue: 1
}

File2.qml

Item {
    property variant ref: null
    onChanged: ref.someValue = 2;
}

main.qml

File1 {
    item: file1
}
File2 {
    item: file2
    ref: file1
}