QT QML 更改状态 c++
我有一个调用信号的 MouseArea, 我将此信号插入插槽并且它正在工作,我的 C++ 代码正在运行。
但是在 C++ 代码中是否可以更改 QML 状态?
调用信号的按钮代码(OK):
MouseArea {
anchors.fill: parent
onClicked: {
inscriptionCarre.qmlSignalButtonInscription("Button");
}
}
我的状态代码:
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; }
}
]
我想在我的插槽(C++代码)内将状态更改为“loginOK”,这可能吗?
谢谢
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, 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于状态是一个项目属性,因此您应该能够像这样修改它:
参考:http://qt-project.org/doc/qt-4.8/qtbinding.html#modifying-properties
或者从您的 C++ 插槽中,您可以发出一个信号,将状态字符串传递到 QML 插槽这反过来又设置了状态。例如:
C++ 文件:
QML 文件:
Since state is an item property, you should be able to modify it like so:
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:
QML file: