My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtCore/QStateMachine>
#include <QtCore/QState>
#include <QtCore/QFinalState>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton button("Ok");

/* The state machine. */
QStateMachine machine;

/* Three states to the state machine. */
QState s1;
QState s2;
QState s3;

/* For each state it sets the button's text property. */
s1.setPropertyOnEntry(&button, "text", "In state S[1]");
s2.setPropertyOnEntry(&button, "text", "In state S[2]");
s3.setPropertyOnEntry(&button, "text", "In state S[3]");

/* Adds the transitions to each state */
s1.addTransition(&button, SIGNAL(clicked()), &s2);
s2.addTransition(&button, SIGNAL(clicked()), &s3);
s3.addTransition(&button, SIGNAL(clicked()), &s1);

/* Adds the three states s1, s2 and s3 to the state machine. */
machine.addState(&s1);
machine.addState(&s2);
machine.addState(&s3);

/* Sets the state s1 as initial state. */
machine.setInitialState(&s1);

/* Starts the state machine. */
machine.start();

button.show();

return a.exec();
}
Show details Hide details

Change log

r2 by ragner.magalhaes on Apr 16, 2009   Diff
A Simple State Machine

Simple example to demonstrate the core
functionality of the State Machine API.

Signed-off-by: Ragner Magalhaes
<ragner.magalhaes@gmail.com>
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1181 bytes, 44 lines
Hosted by Google Code