QScxmlCppDataModel¶
The
QScxmlCppDataModel
class is a C++ data model for a Qt SCXML state machine. More…
New in version 5.12.
Synopsis¶
Functions¶
def
inState
(stateName)def
scxmlEvent
()
Detailed Description¶
The C++ data model for SCXML lets you write C++ code for expr attributes and
<script>
elements. The data part of the data model is backed by a subclass ofQScxmlCppDataModel
, for which the Qt SCXML compiler (qscxmlc
) will generate the dispatch methods. It cannot be used when loading an SCXML file at runtime.Usage is through the datamodel attribute of the
<scxml>
element:<scxml datamodel="cplusplus:TheDataModel:thedatamodel.h" ....>The format of the datamodel attribute is:
cplusplus:<class-name>:<classdef-header>
. So, for the example above, there should be a file thedatamodel.h containing a subclass ofQScxmlCppDataModel
, containing at least the following:#include "qscxmlcppdatamodel.h" class TheDataModel: public QScxmlCppDataModel { Q_OBJECT Q_SCXML_DATAMODEL };The Q_SCXML_DATAMODEL has to appear in the private section of the class definition, for example right after the opening bracket, or after a
Q_OBJECT
macro. This macro expands to the declaration of some virtual methods whose implementation is generated by the Qt SCXML compiler.The Qt SCXML compiler will generate the various
evaluateTo
methods, and convert expressions and scripts into lambdas inside those methods. For example:<scxml datamodel="cplusplus:TheDataModel:thedatamodel.h" xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="MediaPlayerStateMachine"> <state id="stopped"> <transition event="tap" cond="isValidMedia()" target="playing"/> </state> <state id="playing"> <onentry> <script> media = eventData().value(QStringLiteral("media")).toString(); </script> <send event="playbackStarted"> <param name="media" expr="media"/> </send> </onentry> </state> </scxml>This will result in:
bool TheDataModel::evaluateToBool(QScxmlExecutableContent::EvaluatorId id, bool *ok) { // .... return [this]()->bool{ return isValidMedia(); }(); // .... } QVariant TheDataModel::evaluateToVariant(QScxmlExecutableContent::EvaluatorId id, bool *ok) { // .... return [this]()->QVariant{ return media; }(); // .... } void TheDataModel::evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) { // .... [this]()->void{ media = eventData().value(QStringLiteral("media")).toString(); }(); // .... }So, you are not limited to call functions. In a
<script>
element you can put zero or more C++ statements, and in cond or expr attributes you can use any C++ expression that can be converted to the respective bool orQVariant
. And, as thethis
pointer is also captured, you can call or access the data model (the media attribute in the example above). For the full example, see Qt SCXML: Media Player QML Example (C++ Data Model) .See also
- class PySide2.QtScxml.QScxmlCppDataModel([parent=None])¶
- param parent:
Creates a new C++ data model with the parent object
parent
.
- PySide2.QtScxml.QScxmlCppDataModel.inState(stateName)¶
- Parameters:
stateName – str
- Return type:
bool
Returns
true
if the state machine is in the state specified bystateName
,false
otherwise.
- PySide2.QtScxml.QScxmlCppDataModel.scxmlEvent()¶
- Return type:
Holds the current event that is being processed by the state machine.
See also SCXML Specification - 5.10 System Variables for the description of the
_event
variable.Returns the event currently being processed.
See also
setScxmlEvent()
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.