Qt状态机框架连接信号
在Qt状态机框架文档中有一个如何设置属性的示例状态激活:
s1->assignProperty(label, "text", "In state s1");
s2->assignProperty(label, "text", "In state s2");
s3->assignProperty(label, "text", "In state s3");
有没有办法在状态激活时连接插槽?就像 s1_buttonclick
仅在 s1
处于活动状态时才会连接,s2_buttonclick
仅在 s2
处于活动状态时才会连接?
In the Qt State Machine Framework documentation there is an example how to set properties on state activation:
s1->assignProperty(label, "text", "In state s1");
s2->assignProperty(label, "text", "In state s2");
s3->assignProperty(label, "text", "In state s3");
Is there a way to connect slots on state activation? like s1_buttonclick
will only be connected when s1
is active and s2_buttonclick
will only be connected when s2
is active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望连接根据状态机当前所处的状态而有所不同?
我认为您必须使用其他插槽以及 Entered() 和 Exited() 信号自行管理。只需为各州的每个入口和出口创建一个插槽即可。
You want the connections to be different based on which state the state machine is currently in?
I think you will have to manage this yourself using other slots and the entered() and exited() signals. Just create a slot for the each entrance and exit of the states.
可以使用代表连接并提供连接的活动属性的辅助类来完成过滤信号槽连接。请注意,Qt 5 的
QMetaObject::Connection
对此还不够。Filtering signal-slot connections can be done using a helper class that represents a connection and provides an active property of the connection. Note that Qt 5's
QMetaObject::Connection
is not sufficient for this.