I want to create a custom QML component with two properties one
and two
, which should have default values when left uninitialized. In particular, i
Double check that there is not need to Binding and be careful about not making codes dirty.
You can fill property with value very soon as follows:
window {
id: win
width: 300; height: 450
color: "#d8d8d8"
Item {
property int val1
property int val2
property int val3: parent.width //<-- Binding
Component.onCompleted: {
val1 = win.width; //<---|
val2 = win.height; //<---|=== There is no binding. Just changes value
/* ... */
}
}
}
(I am not sure, you may be able to set initial value using Component.onStatusChanged
and Component.Ready
status)
Notice for Performance: Signal and Javascript codes have some performance impact. It may be more performant to use bindings. Use Profiler to check that. If you want to set initial values of multiple property or you have already used onCompleted
signal, so this will improve the performance!