开发者

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
     }
}
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜