I have an rectangle in which I am calling a statement on its onComplted block. But I dont know the statement gets executed 3 times instead of only 1. Here is my code
Rectangle {
id: selector_button;
signal clicked
state: 'pressed'
MouseArea {
anchors.fill: parent;
onPressed: {
selector_button.state == 'pressed' ? selector_button.state = "" : selector_button.state = 'pressed';
Current.currentData("Enbaled");
selector_button.clicked();
}
}
states: [
State {
name: "pressed"
PropertyChanges { target: selector_button; color: "#fg08Rf" }
}
]
Component.onCompleted: {
Current.currentData("Enabled"); */
}
}
But I use this component in other qml files as well, is it the issue...? if yes where shall I call this statement so that it executes only once Similar things are happening on some onPropertyChanged ...any idea what I am doing wrong
This is because of the state fast forwarding, the qml engine parsing and initialized EACH state before rendering phase.
Ref. http://qt-project.org/doc/qt-4.8/qdeclarativestates.html#state-fast-forwarding
This is more like undefined behavior of QML, and your logic or value binding should not rely on this "feature"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With