转型Qt小半年了,看到项目组用的Qt state machine signal和匿名函数满天飞,就想之前用的C#里的QF state machine 能不能做转到Qt平台。这样可以省去使用Qt状态机的信号,在这过程中学习借鉴了QF state machine 的鼻祖 QP框架,不知道有没有嵌入式的小伙伴比较熟悉这个。据说是嵌入式的集大成者。

先上个成果,QF 和QT两种状态机实现上图的状态转换,下图是时间对比,QF的优势还是可以的。

下面先介绍一下QF的大概结构
QFState: 实际就是一个函数指针,包装有函数名称,用于扩展比较的。
QHsm:实现状态机的转换。Trigger用于切换状态。但是同理于Qt状态机,不能无限无信号跳转,否则堆栈溢出。
QActive:继承QHsm和QThread,可以独立执行,不需要操作线程。
QF:能够实现多 QActive之间的信号交互。
上源代码
chen15861132927/QF4CPlus (github.com) https://github.com/chen15861132927/QF4CPlus
https://github.com/chen15861132927/QF4CPlus
主要参考
zdomokos/qf4net: C# port of Miro Samek's Quantum Framework including his excellent implementation of a hierarchical state machine. (github.com) https://github.com/zdomokos/qf4netqpcpp/examples at master · QuantumLeaps/qpcpp (github.com)
https://github.com/zdomokos/qf4netqpcpp/examples at master · QuantumLeaps/qpcpp (github.com) https://github.com/QuantumLeaps/qpcpp/tree/master/examples
https://github.com/QuantumLeaps/qpcpp/tree/master/examples


![[附源码]计算机毕业设计港口集团仓库管理系统Springboot程序](https://img-blog.csdnimg.cn/fcd06f6f2ef149a6b11440f5555f4000.png)





![[附源码]Node.js计算机毕业设计电商后台管理系统Express](https://img-blog.csdnimg.cn/b2e4bac576bb428d8f529f547a7e13e5.png)










