CopperSpice API  1.7.2
QState Class Reference

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

Inheritance diagram for QState:
QAbstractState QObject QStateMachine

Public Types

enum  ChildMode
 
enum  RestorePolicy
 

Public Signals

void childModeChanged ()
 
void errorStateChanged ()
 
void finished ()
 
void initialStateChanged ()
 
void propertiesAssigned ()
 
- Public Signals inherited from QAbstractState
void activeChanged (bool active)
 
void entered ()
 
void exited ()
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QState (ChildMode childMode, QState *parent=nullptr)
 
 QState (QState *parent=nullptr)
 
 ~QState ()
 
QAbstractTransitionaddTransition (QAbstractState *target)
 
void addTransition (QAbstractTransition *transition)
 
template<class SignalClass , class... SignalArgs>
QSignalTransitionaddTransition (QObject *sender, void (SignalClass::*signal)(SignalArgs...), QAbstractState *target)
 
void assignProperty (QObject *object, const QString &name, const QVariant &value)
 
ChildMode childMode () const
 
QAbstractStateerrorState () const
 
QAbstractStateinitialState () const
 
void removeTransition (QAbstractTransition *transition)
 
void setChildMode (ChildMode mode)
 
void setErrorState (QAbstractState *state)
 
void setInitialState (QAbstractState *state)
 
QList< QAbstractTransition * > transitions () const
 
- Public Methods inherited from QAbstractState
 ~QAbstractState ()
 
bool active () const
 
QStateMachinemachine () const
 
QStateparentState () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

bool event (QEvent *e) override
 
void onEntry (QEvent *event) override
 
void onExit (QEvent *event) override
 
- Protected Methods inherited from QAbstractState
 QAbstractState (QState *parent=nullptr)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 childMode
 
 errorState
 
 initialState
 
- Properties inherited from QAbstractState
 active
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

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 State Machine.

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).

See also
propertiesAssigned()

Member Enumeration Documentation

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

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

This enum specifies the restore policy type. The restore policy takes effect when the machine enters a state which sets one or more properties. If the restore policy is set to RestoreProperties, the state machine will save the original value of the property before the new value is set.

Later when the machine either enters a state which does not set a value for the given property, the property will automatically be restored to its initial value.

Only one initial value will be saved for any given property. If a value for a property has already been saved by the state machine, it will not be overwritten until the property has been successfully restored.

ConstantValueDescription
QStateMachine::DontRestoreProperties0 The state machine should not save the initial values of properties and restore them later.
QStateMachine::RestoreProperties1 The state machine should save the initial values of properties and restore them later.
See also
QStateMachine::globalRestorePolicy, QState::assignProperty()

Constructor & Destructor Documentation

QState::QState ( QState *  parent = nullptr)

Constructs a new state with the given parent state.

QState::QState ( ChildMode  childMode,
QState *  parent = nullptr 
)

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

QState::~QState ( )

Destroys this state object.

Method Documentation

QAbstractTransition * QState::addTransition ( QAbstractState target)

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

void QState::addTransition ( QAbstractTransition transition)

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

template<class SignalClass , class... SignalArgs>
QSignalTransition * QState::addTransition ( QObject sender,
void (SignalClass::*)(SignalArgs...)  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.

void QState::assignProperty ( QObject object,
const QString 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()
ChildMode QState::childMode ( ) const

Returns the child mode of this state.

See also
setChildMode()
void QState::childModeChanged ( )
signal

This signal is emitted when the childMode property is changed.

See also
QState::childMode
QAbstractState * QState::errorState ( ) const

Returns this state's error state.

See also
setErrorState(), QStateMachine::error()
void QState::errorStateChanged ( )
signal

This signal is emitted when the errorState property is changed.

See also
QState::errorState
bool QState::event ( QEvent event)
overrideprotectedvirtual

This virtual method receives events to an object and should return true if the event event was recognized and processed. The event() method can be overridden to customize the behavior of an object.

See also
installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), QWidget::event()

Reimplemented from QAbstractState.

Reimplemented in QStateMachine.

void QState::finished ( )
signal

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

See also
QFinalState
QAbstractState * QState::initialState ( ) const

Returns this state's initial state or nullptr if the state has no initial state.

See also
setInitialState()
void QState::initialStateChanged ( )
signal

This signal is emitted when the initialState property is changed.

See also
QState::initialState
void QState::onEntry ( QEvent event)
overrideprotectedvirtual

This function is called when the state is entered. The given event is what caused the state to be entered. Reimplement this function to perform custom processing when the state is entered.

Implements QAbstractState.

Reimplemented in QStateMachine.

void QState::onExit ( QEvent event)
overrideprotectedvirtual

This function is called when the state is exited. The given event is what caused the state to be exited. Reimplement this method to perform custom processing when the state is exited.

Implements QAbstractState.

Reimplemented in QStateMachine.

void QState::propertiesAssigned ( )
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(), QAbstractTransition::addAnimation()
void QState::removeTransition ( QAbstractTransition transition)

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

See also
addTransition()
void QState::setChildMode ( ChildMode  mode)

Sets the child mode of this state to mode.

See also
childMode()
void QState::setErrorState ( QAbstractState state)

Sets this state's error state to be the given state. If the error state is not set, or if it is set to nullptr, the state will inherit its parent's error state recursively. If no error state is set for the state itself or any of its ancestors, an error will cause the machine to stop executing and an error will be printed to the console.

See also
errorState()
void QState::setInitialState ( QAbstractState state)

Sets this state's initial state to be the given state. The state has to be a child of this state.

See also
initialState()
QList< QAbstractTransition * > QState::transitions ( ) 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()

Property Documentation

QState::childMode

This property holds the child mode of this state. The default value of this property is QState::ExclusiveStates.

PropertiesClass Methods
read childMode
write setChildMode
notify childModeChanged
QState::errorState

This property holds the error state of this state.

PropertiesClass Methods
read errorState
write setErrorState
notify errorStateChanged
QState::initialState

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

PropertiesClass Methods
read initialState
write setInitialState
notify initialStateChanged