JNI_OnLoad
JNI_OnLoad

Reputation: 5442

multiple times statement execution in Component.onCompleted qml

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

Upvotes: 3

Views: 1440

Answers (1)

Longwei
Longwei

Reputation: 66

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"

Upvotes: 2

Related Questions