本页内容

QScxmlDataModel Class

QScxmlDataModel 类是Qt SCXML 状态机的数据模型基类。更多内容...

头文件: #include <QScxmlDataModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Scxml)
target_link_libraries(mytarget PRIVATE Qt6::Scxml)
qmake: QT += scxml
继承自: QObject
继承自:

QScxmlCppDataModel 以及QScxmlNullDataModel

公共类型

属性

公共函数

QScxmlDataModel(QObject *parent = nullptr)
QBindable<QScxmlStateMachine *> bindableStateMachine()
virtual void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, QScxmlDataModel::ForeachLoopBody *body) = 0
virtual void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual bool evaluateToBool(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual QString evaluateToString(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual QVariant evaluateToVariant(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual void evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0
virtual bool hasScxmlProperty(const QString &name) const = 0
virtual QVariant scxmlProperty(const QString &name) const = 0
virtual void setScxmlEvent(const QScxmlEvent &event) = 0
virtual bool setScxmlProperty(const QString &name, const QVariant &value, const QString &context) = 0
void setStateMachine(QScxmlStateMachine *stateMachine)
virtual bool setup(const QVariantMap &initialDataValues) = 0
QScxmlStateMachine *stateMachine() const

信号

void stateMachineChanged(QScxmlStateMachine *stateMachine)

静态公共成员

QScxmlDataModel *createScxmlDataModel(const QString &pluginKey)

受保护函数

QScxmlDataModel(QScxmlDataModelPrivate &dd, QObject *parent = nullptr)

详细说明

SCXML 数据模型在《SCXML 规范——第 5 章 数据模型与数据操作》中进行了描述。有关受支持的数据模型的更多信息,请参阅“SCXML 兼容性”。

一个数据模型只能属于一个状态机。

另请参阅 QScxmlStateMachine 、QScxmlCppDataModel 以及QScxmlNullDataModel 。

属性文档

[bindable] stateMachine : QScxmlStateMachine*

注意:该 属性支持QProperty 绑定。

该属性存储了该数据模型所属的状态机。

一个数据模型只能属于一个状态机,而一个状态机也只能包含一个数据模型。这种关联必须在状态机启动之前建立。在数据模型上设置此属性将自动在stateMachine 上设置相应的dataModel 属性。

访问函数:

QScxmlStateMachine *stateMachine() const
void setStateMachine(QScxmlStateMachine *stateMachine)

通知器信号:

void stateMachineChanged(QScxmlStateMachine *stateMachine)

成员函数文档

[explicit] QScxmlDataModel::QScxmlDataModel(QObject *parent = nullptr)

创建一个新的数据模型,其父对象为parent 。

[explicit protected] QScxmlDataModel::QScxmlDataModel(QScxmlDataModelPrivate &dd, QObject *parent = nullptr)

根据私有对象dd 创建一个新的数据模型,其父对象为parent 。

[static] QScxmlDataModel *QScxmlDataModel::createScxmlDataModel(const QString &pluginKey)

根据pluginKey 指定的插件创建一个数据模型。

[pure virtual] void QScxmlDataModel::evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估由id 指向的赋值表达式,并在发生错误时将ok 设置为false ,若未发生错误则将其设置为true 。

[pure virtual] void QScxmlDataModel::evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, QScxmlDataModel::ForeachLoopBody *body)

评估由id 指向的foreach循环,并在出现错误时将ok 设置为false ,若未出现错误则设置为true 。body 将在每次迭代时执行。

[pure virtual] void QScxmlDataModel::evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估id 所指向的初始化内容,并在出现错误时将ok 设置为false ,若未出现错误则将其设置为true 。

[pure virtual] bool QScxmlDataModel::evaluateToBool(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估由id 指向的可执行内容,并在出现错误时将ok 设置为false ,未出现错误时则设置为true 。返回评估结果,该结果为布尔值。

[pure virtual] QString QScxmlDataModel::evaluateToString(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估由id 指向的可执行内容,并在出现错误时将ok 设置为false ,若无错误则设置为true 。将评估结果作为QString 返回。

[pure virtual] QVariant QScxmlDataModel::evaluateToVariant(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估由id 指向的可执行内容,并在出现错误时将ok 设置为false ,若未出现错误则设置为true 。将评估结果作为QVariant 返回。

[pure virtual] void QScxmlDataModel::evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok)

评估由id 指向的可执行内容,并将ok 设置为false (若发生错误)或true (若未发生错误)。该执行操作预计不会返回任何结果。

[pure virtual] bool QScxmlDataModel::hasScxmlProperty(const QString &name) const

如果存在具有给定name 的属性,则返回true ;否则返回false 。

[pure virtual] QVariant QScxmlDataModel::scxmlProperty(const QString &name) const

返回属性name 的值。

另请参阅 setScxmlProperty()。

[pure virtual] void QScxmlDataModel::setScxmlEvent(const QScxmlEvent &event)

设置后续可执行内容执行时要使用的event 。

[pure virtual] bool QScxmlDataModel::setScxmlProperty(const QString &name, const QVariant &value, const QString &context)

将属性name 的值设置为value 。

context 是一个字符串,用于在错误消息中指示 SCXML 文件中发生错误的位置。

如果成功,则返回true ;如果发生错误,则返回false 。

另请参阅 scxmlProperty()。

void QScxmlDataModel::setStateMachine(QScxmlStateMachine *stateMachine)

将该模型所属的状态机设置为stateMachine 。状态机与模型之间存在1:1的对应关系。状态机一旦设置,便无法再进行更改。此后任何尝试使用此方法设置状态机的操作都将被忽略。

注意: 这是属性stateMachine 的设置 函数。

另请参阅 stateMachine()。

[pure virtual invokable] bool QScxmlDataModel::setup(const QVariantMap &initialDataValues)

使用initialDataValues 中指定的初始值初始化数据模型。

如果发生解析错误或任何初始化步骤失败,则返回false 。否则返回true 。

注意: 可通过元对象系统以及从 QML 中调用此 函数。请参阅Q_INVOKABLE 。

QScxmlStateMachine *QScxmlDataModel::stateMachine() const

返回与数据模型关联的状态机。

注意: 这是 stateMachine 属性的获取函数 。

另请参阅 setStateMachine()。

© 2026 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.