QScxmlParser Class

The QScxmlParser class is a parser for SCXML files. More...

Header: #include <QScxmlParser>
qmake: QT += scxml
Since: Qt 5.7

Public Types

class Loader
enum QtMode { QtModeDisabled, QtModeEnabled, QtModeFromInputFile }

Public Functions

QScxmlParser(QXmlStreamReader *reader)
void addError(const QString &msg)
QVector<QScxmlError> errors() const
QString fileName() const
void instantiateDataModel(QScxmlStateMachine *stateMachine) const
QScxmlStateMachine *instantiateStateMachine() const
Loader *loader() const
void parse()
QtMode qtMode() const
void setFileName(const QString &fileName)
void setLoader(Loader *newLoader)
void setQtMode(QtMode mode)

Detailed Description

The QScxmlParser class is a parser for SCXML files.

Parses an SCXML file. It can also dynamically instantiate a state machine for a successfully parsed SCXML file. If parsing failed and instantiateStateMachine() is called, the new state machine cannot start. All errors are returned by QScxmlStateMachine::parseErrors().

To load an SCXML file, QScxmlStateMachine::fromFile or QScxmlStateMachine::fromData should be used. Using QScxmlParser directly is only needed when the parser needs to use a custom QScxmlParser::Loader.

Member Type Documentation

enum QScxmlParser::QtMode

This enum specifies if the document should be parsed in Qt mode. In Qt mode, event and state names have to be valid C++ identifiers. If that is the case some additional convenience methods are generated. If not, the parser will reject the document. Qt mode can be enabled in the document itself by adding an XML comment of the form:

<!-- enable-qt-mode: yes -->

QScxmlParser::QtModeDisabled0Ignore the XML comment and do not generate additional methods.
QScxmlParser::QtModeEnabled1Force parsing in Qt mode and try to generate the additional methods, no matter if the XML comment is present.
QScxmlParser::QtModeFromInputFile2Enable Qt mode only if the XML comment is present in the document.

Member Function Documentation

QScxmlParser::QScxmlParser(QXmlStreamReader *reader)

Creates a new SCXML parser for the specified reader.


Destroys the SCXML parser.

void QScxmlParser::addError(const QString &msg)

Adds the error message msg.

The line and column numbers for the error message are the current line and column numbers of the QXmlStreamReader.

QVector<QScxmlError> QScxmlParser::errors() const

Returns the list of parse errors.

QString QScxmlParser::fileName() const

Returns the file name associated with the current input.

See also setFileName().

void QScxmlParser::instantiateDataModel(QScxmlStateMachine *stateMachine) const

Instantiates the data model as described in the SCXML file.

After instantiation, the stateMachine takes ownership of the data model.

QScxmlStateMachine *QScxmlParser::instantiateStateMachine() const

Instantiates a new state machine from the parsed SCXML.

If parsing is successful, the returned state machine can be initialized and started. If parsing fails, QScxmlStateMachine::parseErrors() can be used to retrieve a list of errors.

Note: The instantiated state machine will not have an associated data model set.

See also QScxmlParser::instantiateDataModel.

Loader *QScxmlParser::loader() const

Returns the loader that is currently used to resolve and load URIs.

See also setLoader().

void QScxmlParser::parse()

Parses an SCXML file.

QtMode QScxmlParser::qtMode() const

Returns how the parser decides if the SCXML document should conform to Qt mode.

See also setQtMode() and QtMode.

void QScxmlParser::setFileName(const QString &fileName)

Sets the file name for the current input to fileName.

The file name is used for error reporting and for resolving relative path URIs.

See also fileName().

void QScxmlParser::setLoader(Loader *newLoader)

Sets newLoader to be used for resolving and loading URIs.

See also loader().

void QScxmlParser::setQtMode(QtMode mode)

Sets the qtMode to mode. This property overrides the XML comment. You can force Qt mode to be used by setting it to QtModeEnabled or force any XML comments to be ignored and Qt mode to be used by setting it to QtModeDisabled. The default is QtModeFromInputFile, which will switch Qt mode on if the XML comment is present in the source file.

See also qtMode() and QtMode.

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