QState Class Reference

The QState class provides a general-purpose state for QStateMachine.

  1. #include <QState>

Inherits: QAbstractState.

Inherited by: QStateMachine.

This class was introduced in Qt 4.6.

Detailed Description

The QState class provides a general-purpose state for QStateMachine.

QState objects can have child states, and can have transitions to other states. QState is part of The State Machine Framework.

The addTransition() function adds a transition. The removeTransition() function removes a transition. The transitions() function returns the state's outgoing transitions.

The assignProperty() function is used for defining property assignments that should be performed when a state is entered.

Top-level states must be passed a QStateMachine object as their parent state, or added to a state machine using QStateMachine::addState().

States with Child States

The childMode property determines how child states are treated. For non-parallel state groups, the setInitialState() function must be called to set the initial state. The child states are mutually exclusive states, and the state machine needs to know which child state to enter when the parent state is the target of a transition.

The state emits the QState::finished() signal when a final child state (QFinalState) is entered.

The setErrorState() sets the state's error state. The error state is the state that the state machine will transition to if an error is detected when attempting to enter the state (e.g. because no initial state has been set).

Public Types

Toggle detailsenum QState::

ChildModeChildMode { ExclusiveStates , ParallelStates 1 ...} { ExclusiveStates , ParallelStates 1 }

This enum specifies how a state's child states are treated.

ConstantValueDescription
QState::ExclusiveStates 0 The child states are mutually exclusive and an initial state must be set by calling QState::setInitialState().
QState::ParallelStates 1 The child states are parallel. When the parent state is entered, all its child states are entered in parallel.

Look up this member in the source code.

    Properties

    Toggle detailschildModechildMode : ChildMode

    This property holds the child mode of this state

    The default value of this property is QState::ExclusiveStates.

    Access functions:

    Look up this member in the source code.

    Toggle detailserrorStateerrorState : QAbstractState *

    This property holds the error state of this state

    Access functions:

    Look up this member in the source code.

    Toggle detailsinitialStateinitialState : QAbstractState *

    This property holds the initial state of this state (one of its child states)

    Access functions:

    Look up this member in the source code.

      Public Functions

      Toggle details QState

      QStateQState ( QState *parent=0 ) ( QState *parent=0 )

      Constructs a new state with the given parent state.

      Look up this member in the source code.

      Toggle details QState

      QStateQState ( ChildMode childMode , QState *parent=0 ) ( ChildMode childMode , QState *parent=0 )

      Constructs a new state with the given childMode and the given parent state.

      Look up this member in the source code.

      Toggle details QState

      ~QState~QState () ()

      Destroys this state.

      Look up this member in the source code.

      Toggle details void QState

      addTransitionaddTransition ( QAbstractTransition *transition ...) ( QAbstractTransition *transition )

      Adds the given transition. The transition has this state as the source. This state takes ownership of the transition.

      Look up this member in the source code.

      Toggle details QSignalTransition * QState

      addTransitionaddTransition ( QObject *sender , const char *signal , QAbstractState *target ...) ( QObject *sender , const char *signal , QAbstractState *target )

      Adds a transition associated with the given signal of the given sender object, and returns the new QSignalTransition object. The transition has this state as the source, and the given target as the target state.

      Look up this member in the source code.

      Toggle details QAbstractTransition * QState

      addTransitionaddTransition ( QAbstractState *target ...) ( QAbstractState *target )

      Adds an unconditional transition from this state to the given target state, and returns then new transition object.

      Look up this member in the source code.

      Toggle details void QState

      assignPropertyassignProperty ( QObject *object , const char *name , const QVariant &value ...) ( QObject *object , const char *name , const QVariant &value )

      Instructs this state to set the property with the given name of the given object to the given value when the state is entered.

      See also propertiesAssigned().

      Look up this member in the source code.

      Toggle details bool QState

      eventevent ( QEvent *e ) ( QEvent *e ) [virtual protected]

      Reimplemented from QObject::event().

      Look up this member in the source code.

      Toggle details void QState

      onEntryonEntry ( QEvent *event ) ( QEvent *event ) [virtual protected]

      Reimplemented from QAbstractState::onEntry().

      Look up this member in the source code.

      Toggle details void QState

      onExitonExit ( QEvent *event ) ( QEvent *event ) [virtual protected]

      Reimplemented from QAbstractState::onExit().

      Look up this member in the source code.

      Toggle details void QState

      removeTransitionremoveTransition ( QAbstractTransition *transition ...) ( QAbstractTransition *transition )

      Removes the given transition from this state. The state releases ownership of the transition.

      See also addTransition().

      Look up this member in the source code.

      Toggle details QList <QAbstractTransition *> QState

      transitionstransitions () ()const

      Returns this state's outgoing transitions (i.e. transitions where this state is the source state), or an empty list if this state has no outgoing transitions.

      See also addTransition().

      Look up this member in the source code.

        Signals

        Toggle details void QState

        finishedfinished () () [signal]

        This signal is emitted when a final child state of this state is entered.

        See also QFinalState.

        Look up this member in the source code.

        Toggle details void QState

        propertiesAssignedpropertiesAssigned () () [signal]

        This signal is emitted when all properties have been assigned their final value. If the state assigns a value to one or more properties for which an animation exists (either set on the transition or as a default animation on the state machine), then the signal will not be emitted until all such animations have finished playing.

        If there are no relevant animations, or no property assignments defined for the state, then the signal will be emitted immediately before the state is entered.

        See also QState::assignProperty() and QAbstractTransition::addAnimation().

        Look up this member in the source code.

          Notes provided by the Qt Community

          No notes