QT QML change state c++
i've a MouseArea that call a signal, i plug this signal to a slot and it's working, my c++ code is running.
But is it possible inside c++ code,开发者_Python百科 change the QML state ?
code of button that call signal (OK) :
MouseArea {
anchors.fill: parent
onClicked: {
inscriptionCarre.qmlSignalButtonInscription("Button");
}
}
Code of my states :
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 inside my slot (c++ code) change state to "loginOK", is it possible ?
Thanks
Since state is an item property, you should be able to modify it like so:
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, "MyItem.qml");
QObject *object = component.create();
object->setProperty("state", "loginOK");
Reference: http://qt-project.org/doc/qt-4.8/qtbinding.html#modifying-properties
Or from your C++ slot you could emit a signal that passes the state string to a QML slot that in turn sets the state. For example like:
C++ file:
...
signals:
void stateChanged(const QString &newState);
...
QML file:
...
MyItem {
onStateChanged: {
state: newState
}
}
...
精彩评论