This is a simple example for the Qt SCXML integration of CREATE Statechart Tools. The example is inspired by the traffic light examples that can be found here. The example uses a manually made statechart model from which a scxml-file is generated, which then can be executed as a standalone application within the QT environment. The manually made statechart model looks as follows:
The main part of the statechart consists of two composite states "working" and "broken". Each of the states has several substates for the different modes of a traffic light.To run this example an installation of Qt is needed. It is recommended to use the latest version, but at least Qt 5.10.1 with Qt Creator 4.6.1. We also recommend to use MinGW 5.3.0 and CMake for building the project when using Windows.
To check the compiler configuration, navigate to 'Tools > Options ... > Build & Run > Compilers' in your Qt installation.
The example project contains several files which declare the behaviour and look-and-feel of the traffic light:
To setup the trafficlight project you will first need to generate the .scxml statemachine file.
The 'TrafficLightStateMachine.scxml' should be created in the 'src-gen' folder.
The project should be opened and build automatically.
The traffic light application should be started. A traffic light which consists of a red, yellow and green bulb is displayed and is switching between the states. The traffic light can be set to broken/repaired by clicking on the 'Pause/Play' button at the bottom right, see the following image:
You can run Qt Unit tests to test the traffic light statemachine behaviour. For this Itemis CREATE provides a SCTUnit code generator which generates a whole Qt Unit test project.
The folder 'test-gen' should be created containing the QtSCTUnit project with a reference to the statechart defined in 'TrafficLightStateMachine.scxml' which can be loaded into Qt.
Additionally you can simulate the statechart in CREATE Statechart Tools by right-click on the 'TrafficLightStateMachine.sct' file and choose:
You'll find more information on using the simulation in the help.