简体   繁体   English

如何在QStateMachine中管理事件?

[英]How are managed the events in QStateMachine?

I work with a state machine based on QScxmlStateMachine . 我使用基于QScxmlStateMachine的状态机。 Some transitions are automatically triggered by code in the onEntry handlers, some others are triggered by external events (such as user click). 有些转换是由onEntry处理程序中的代码自动触发的,而另一些则是由外部事件(例如用户单击)触发的。

The execution of the state machine is asynchronous. 状态机的执行是异步的。 This code is not blocking : 这段代码没有阻塞:

m_statemachine->submitEvent("user_initialize", settings);

Fine. 精细。 What I want to know is how the processing inside the state machine is done then. 我想知道的是状态机内部的处理是如何完成的。
This first event is queued and will asynchronously enter in a state initializing , what about the events that could be triggered in this state onEntry code, are they queued too ? 第一个事件已排队,并且将异步进入初始化状态,那么在onEntry代码的此状态下可能触发的事件又如何呢?
Does the internal event-loop could process some other GUI events before processing the next transition ? 内部事件循环是否可以在处理下一个转换之前处理其他一些GUI事件?
And, I assume not, is the state-machine event-loop in a separate thread ? 而且,我认为不是,状态机事件循环是否在单独的线程中?

This first event is queued and will asynchronously enter in a state initializing, what about the events that could be triggered in this state onEntry code, are they queued too ? 第一个事件已排队,并且将异步进入初始化状态,那么在onEntry代码的此状态下可能触发的事件又如何呢?

All events are queued. 所有事件都已排队。 The Qt term for these is posted events (as opposed to sent events that execute immediately). 这些事件的Qt术语是发布事件(与立即执行的已发送事件相反)。

And, I assume not, is the state-machine event-loop in a separate thread ? 而且,我认为不是,状态机事件循环是否在单独的线程中?

The "internal" event loop is a bit of a misnomer. “内部”事件循环有点用词不当。 The state machine really runs on the current thread's event loop, but it copies some of the events and processes them later. 状态机确实在当前线程的事件循环上运行,但是它会复制一些事件并在以后处理它们。

Does the internal event-loop could process some other GUI events before processing the next transition? 内部事件循环是否可以在处理下一个转换之前处理其他一些GUI事件?

Yes. 是。 You're only guaranteed the relative event processing order within the state machine itself. 您只能保证状态机本身中的相对事件处理顺序。 Any number of events could be processed between each event delivered to the state machine. 在传递给状态机的每个事件之间可以处理任何数量的事件。 That's always the case no matter what sort of event processing you're doing. 无论您正在执行哪种事件处理,总是如此。 The only way to circumvent it is to post higher-priority events. 规避此问题的唯一方法是发布更高优先级的事件。 Multiple event priorities carry their own drawbacks and must be used with caution and understanding of how the priority scheme is implemented in the event queue. 多个事件优先级有其自身的缺点,必须谨慎使用,并了解事件队列中如何实现优先级方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM