Qt Lab #3 : Statecharts

Eric Lecolinet - Télécom Paris - Dept. INFRES

Useful links


The goal of this Lab is to implement the presentation and interaction parts of the control panel of an (actual) microwave oven.


Step 1: Design the Statechart

Draw (on a sheet of paper [think about taking a picture]) or using a computer tool) the Statechart implementing the desired behaviour.

The buttons on the microwave panel are:

Note that, when a setting sequence is started, no other button is active, except the Stop button, which cancels any operation. For instance:

The Start button can be clicked:

The display panel shows different information depending on currently active state. For instance:


Step 2: Create the graphical interface using QtCreator

You can now create the graphical objects GUI, either by using Qt Designor (which is part of Qt Creator) or by programming them directly. Think about giving intelligible names to your widgets to make programming easier in the following questions.


Step 3: Implement the Statechart and link it to the GUI

You can now implement the QtStateMachine, its states and its transitions. This should typically this be done in the constructor of the MainWindow (or in a method called by the constructor). The Transitions.h header may help the writing the Statechart.

We will take care of temporal aspects (for displaying the current time on the clock and stopping the oven) in the next question. As said before, the display panel should show appropriate info depending on the selected state.

Once the implementation is completed, do some testing to verify that the behavior is consistent with the specification set out in the previous question.

Step 4: Clock and cooking duration

The goal is now to make the clock to work properly and the oven to stop cooking when the duration has expired. For this purpose you'll need using QTimers. As said before, be careful to update the display only in the appropriate states.

Note: The management of the firing time has a little subtlety. It is necessary to update the display to show the remaining time (every second) but also stop the oven when the time is up. QTimer has a signal to signal that a lapse of time has elapsed, but how to generate a signal when the time has elapsed to trigger the corresponding transition?

Last Etape: Improving the GUI

Give free rein to your imagination... :-)

Exercice Report

Please follow the following instructions to avoid mistakes and undesirable problems:

Eric Lecolinet - http://www.telecom-paristech.fr/~elc - Telecom ParisTech