The state machine framework)

Source: Internet
Author: User

Author: Liu Xuhui Raymond reprinted. Please indicate the source
Email: colorant@163.com
Blog: http://blog.csdn.net/colorant/

Qt's state machine framework is introduced in qt4.6. Its theoretical basis is Harel's statechart. by defining a series of possible states, and how the system converts (transitions between States) in these States to describe the operation of the entire state machine.

State machine architecture
Qt's state machine system consists of three modules:

The qstate of the qabstractstate class and the qfinalstate and qhistorystate class that indicate the state.
Class Based on qiniacttransition used to represent various transition actions (including event triggering, signal triggering, mouse and keyboard triggering, and so on)
Qstatemachine state machine class
Features
Basic functions
A state machine itself defines State transformation and does nothing. Such a state machine is useless.

The qstate class can be bound to a control property. When entering this State, set this property value
You can also run the specified slot function by connecting the entered and exited signals of qstate.
State machine exit
You can define a state machine that never ends, or add an "end state" to the state machine through qfinalstate. After the state machine is converted to this state, the whole state machine ends and exits.

Status nesting
The State itself can be nested, and a large state can be subdivided into sub-State. It can be implemented through the State nesting mechanism and parallel State mechanism.
Status conversion grouping (for example, one Transtion can be used to change the status of a group to another, for example, to return the key)
Parallel monitoring of multiple state transition parameters to avoid creating too many independent States (because if each parameter is mutually exclusive, the number of States is O (n ^ 2 ))
State conversion is not affected by the nesting mechanism. That is to say, you can define the transition from any level of State to other States.

Animation property value
State conversion can work with the animation class to achieve the animation effect of object attribute values. For some marginal occasions, the State-related class also provides functions to determine whether the attribute value has been assigned a value (if the attribute value is changing during the animation process, the value is not assigned a value ), before the animation is completed, the attribute parameter setting mechanism for early exit of the State is also applied.

Historical Status
The qhistorystate class is a record stack used to track and record historical states, not as I imagined. What is the purpose? Let's see how to use it.

Qhistorystate must be added as a member of a parent status group. When the parent status group exits (switched to another status outside the status group), the current status is automatically recorded in qhistorystate. When the external status is switched back, you do not need to know which status group the original status is. You only need to switch to the historical status cause in the status group.

Therefore, the historical status should be used to record an interrupted status, for example, to jump to an external status to handle some things, and then return to the interrupted status.

Conversion of non-target status
Targetless transitions refers to triggering a q1_acttramsotopm: triggered signal when a state transition action is triggered and not switched to another State. You can link this signal for some processing.

It should be noted that targetless transitions is implemented by initializing a transition class without specifying the target State. If the specified target State is the source State (such as S1-> S1 ), then the status will exit and then enter, triggering the qiniactstate: entered and qiniactstate: Exited signals in turn.

Practical application scenarios
Originally, graphical interface application programming is mostly driven by user interaction. It seems that there is no special need to use the state machine driver for assistance. I don't know what application scenarios are there, is it particularly suitable for the use of state machines?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.