2

I put a RangeSlider which is from QtQuick.Controls 2.x into a Component. I've bound its min.value to my model object, which is a subclass of QObject and has been exposed to QML context.

I can access it from QML using the name: "settings". The control is supposed to read settings in the Loader's onLoaded:{...} to initialize itself. I have a Binding-Object outside of the Loader to write back any changes of the min.value. But the control always set the settings' properties first, so I can not initialize it with settings's perperties.

Loader {
    id: loader
    sourceComponent: ctrl
    onLoaded: {
         loader.item.min = settings.min
    } 
}
Binding {
    target: settings
    property: "min"
    value: loader.item.min.value
}
Component {
    id: ctrl
    Item {
        property alias min: slider.first
        RangeSlider {
            id: slider
            ...
        }
    }
}

I want to assign loader.item.min.value (i.e. slider.first.value) the value of settings.min, but before this assignment happens, the settings.min is changed to slider.first.value. After the user set a new value, I want the settings.min to be set to slider.first.value.

Is there anybody know how to implement this correctly?

1
  • I will try to use setSource method of Loader : object setSource(url source, object properties)
    – Jas6033
    May 11, 2017 at 10:10

1 Answer 1

2

You can use the when-property of the the Binding-Object to deactivate the binding, until you have set the inital value. Set it initally to false, and change it to true in the first line of your onLoaded-handler

Also very interesting is the delayed-property. I can't guarantee you that this will work, but it might be an elegant solution. I have not tried it out yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.