QML QML C ++ Change Status

I have a MouseArea that causes a signal, I connect this signal to the slot and it works, my C ++ code works.

But is it possible to change the state of QML inside C ++ code?

button code that triggers the ringtone (OK):

MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        inscriptionCarre.qmlSignalButtonInscription("Button");
                    }
                }

My status code:

states: [
    State {
        name: "start";
        PropertyChanges { target: home; x: -master.width; }
        PropertyChanges { target: login; x:0; }
    },
    State {
        name: "loginOK";
        PropertyChanges { target: login; x: -master.width; }
        PropertyChanges { target: liste; x:0; }
    }
]

I would like the loginOK state to change inside my slot (C ++ code), is this possible?

thank

+3
source share
1 answer

Since state is a property of an element, you should be able to change it as follows:

QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, "MyItem.qml");
QObject *object = component.create();
object->setProperty("state", "loginOK");

Link: http://qt-project.org/doc/qt-4.8/qtbinding.html#modifying-properties

++ , QML, , , . , :

++:

...
signals:
     void stateChanged(const QString &newState);
...

QML:

...
MyItem {
     onStateChanged: {
         state: newState
     }
}
...
+7

All Articles