Home |
The QtStateMachine class provides a hierarchical finite state machine. More...
#include <QtStateMachine>
Inherits QObject.
Note: All the functions in this class are reentrant.
The QtStateMachine class provides a hierarchical finite state machine.
The QtStateMachine class provides a hierarchical finite state machine based on Statecharts concepts and notation. QtStateMachine is part of The State Machine Framework.
A state machine manages a set of states (QtAbstractState objects) and transitions (QtAbstractTransition objects) between those states; the states and the transitions collectively define a state graph. Once a state graph has been defined, the state machine can execute it. QtStateMachine's execution algorithm is based on the State Chart XML (SCXML) algorithm.
The QtState class provides a state that you can use to set properties and invoke methods on QObjects when the state is entered or exited. This is typically used in conjunction with signals; the signals determine the flow of the state graph, whereas the states' property assignments and method invocations are the actions.
Use the addState() function to add a state to the state machine; alternatively, pass the machine's rootState() to the state constructor. Use the removeState() function to remove a state from the state machine.
The following snippet shows a state machine that will finish when a button is clicked:
QPushButton button; QtStateMachine machine; QtState *s1 = new QtState(); s1->assignProperty(&button, "text", "Click me"); QtFinalState *s2 = new QtFinalState(); s1->addTransition(&button, SIGNAL(clicked()), s2); machine.addState(s1); machine.addState(s2); machine.setInitialState(s1); machine.start();
The setInitialState() function sets the state machine's initial state; this state is entered when the state machine is started.
The start() function starts the state machine. The state machine executes asynchronously, i.e. you need to run an event loop in order for it to make progress. The started() signal is emitted when the state machine has entered the initial state.
The state machine processes events and takes transitions until a top-level final state is entered; the state machine then emits the finished() signal.
The stop() function stops the state machine. The stopped() signal is emitted when the state machine has stopped.
The postEvent() function posts an event to the state machine. This is useful when you are using custom events to trigger transitions.
The rootState() function returns the state machine's root state. All top-level states have the root state as their parent.
See also QtAbstractState and QtAbstractTransition.
This enum type defines errors that can occur in the state machine at run time. When the state machine encounters an unrecoverable error at run time, it will set the error code returned by error(), the error message returned by errorString(), and enter an error state based on the context of the error.
Constant | Value | Description |
---|---|---|
QtStateMachine::NoError | 0 | No error has occurred. |
QtStateMachine::NoInitialStateError | 1 | The machine has entered a QtState with children which does not have an initial state set. The context of this error is the state which is missing an initial state. |
QtStateMachine::NoDefaultStateInHistoryState | 2 | The machine has entered a QtHistoryState which does not have a default state set. The context of this error is the QtHistoryState which is missing a default state. |
See also setErrorState().
This property holds the error state of this state machine.
Access functions:
This property holds the error string of this state machine.
Access functions:
This property holds the initial state of this state machine.
Access functions:
This property holds the root state of this state machine.
Access functions:
Constructs a new state machine with the given parent.
Destroys this state machine.
Adds the given state to this state machine. The state becomes a top-level state (i.e. a child of the rootState()).
If the state is already in a different machine, it will first be removed from its old machine, and then added to this machine.
See also removeState() and rootState().
This signal is emitted when the state machine has finished playing all animations associated with the latest transition (i.e., all properties have reached their target values).
Clears the error string and error code of the state machine.
Returns the error code of the last error that occurred in the state machine.
This signal is emitted when the state machine has reached a top-level final state.
See also QtStateMachine::started().
Returns the global restore policy of the state machine.
See also setGlobalRestorePolicy() and QtActionState::restorePolicy().
Posts the given event for processing by this state machine, with a delay of delay milliseconds.
This function returns immediately. The event is added to the state machine's event queue. Events are processed in the order posted. The state machine takes ownership of the event and deletes it once it has been processed.
You can only post events when the state machine is running.
Removes the given state from this state machine. The state machine releases ownership of the state.
See also addState().
Sets the global restore policy of the state machine to restorePolicy. The default global restore policy is QtAbstractState::DoNotRestoreProperties.
The global restore policy cannot be set to QtAbstractState::GlobalRestorePolicy.
See also globalRestorePolicy() and QtAbstractState::setRestorePolicy().
Starts this state machine. The machine will reset its configuration and transition to the initial state. When a final top-level state is entered, the machine will emit the finished() signal.
See also started(), finished(), stop(), and initialState().
This signal is emitted when the state machine has entered its initial state.
See also QtStateMachine::finished() and QtStateMachine::start().
Returns the list of this state machine's states, or an empty list if the state machine has no states.
Stops this state machine.
See also stopped().
This signal is emitted when the state machine has stopped.
See also QtStateMachine::stop().
Copyright © 2009 Nokia | Trademarks | Qt Solutions |