Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple times statement execution in Component.onCompleted qml

Tags:

qt

qt-quick

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

like image 603
JNI_OnLoad Avatar asked Jul 10 '26 01:07

JNI_OnLoad


1 Answers

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"

like image 174
Longwei Avatar answered Jul 14 '26 02:07

Longwei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!