source: trunk/doc/src/examples/pingpong.qdoc@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \example statemachine/pingpong
44 \title Ping Pong States Example
45
46 The Ping Pong States example shows how to use parallel states together
47 with custom events and transitions in \l{The State Machine Framework}.
48
49 This example implements a statechart where two states communicate by
50 posting events to the state machine. The state chart looks as follows:
51
52 \img pingpong-example.png
53 \omit
54 \caption This is a caption
55 \endomit
56
57 The \c pinger and \c ponger states are parallel states, i.e. they are
58 entered simultaneously and will take transitions independently of
59 eachother.
60
61 The \c pinger state will post the first \c ping event upon entry; the \c
62 ponger state will respond by posting a \c pong event; this will cause the
63 \c pinger state to post a new \c ping event; and so on.
64
65 \snippet examples/statemachine/pingpong/main.cpp 0
66
67 Two custom events are defined, \c PingEvent and \c PongEvent.
68
69 \snippet examples/statemachine/pingpong/main.cpp 1
70
71 The \c Pinger class defines a state that posts a \c PingEvent to the state
72 machine when the state is entered.
73
74 \snippet examples/statemachine/pingpong/main.cpp 2
75
76 The \c PingTransition class defines a transition that is triggered by
77 events of type \c PingEvent, and that posts a \c PongEvent (with a delay
78 of 500 milliseconds) to the state machine when the transition is
79 triggered.
80
81 \snippet examples/statemachine/pingpong/main.cpp 3
82
83 The \c PongTransition class defines a transition that is triggered by
84 events of type \c PongEvent, and that posts a \c PingEvent (with a delay
85 of 500 milliseconds) to the state machine when the transition is
86 triggered.
87
88 \snippet examples/statemachine/pingpong/main.cpp 4
89
90 The main() function begins by creating a state machine and a parallel
91 state group.
92
93 \snippet examples/statemachine/pingpong/main.cpp 5
94
95 Next, the \c pinger and \c ponger states are created, with the parallel
96 state group as their parent state. Note that the transitions are \e
97 targetless. When such a transition is triggered, the source state won't be
98 exited and re-entered; only the transition's onTransition() function will
99 be called, and the state machine's configuration will remain the same,
100 which is precisely what we want in this case.
101
102 \snippet examples/statemachine/pingpong/main.cpp 6
103
104 Finally, the group is added to the state machine, the machine is started,
105 and the application event loop is entered.
106
107 */
Note: See TracBrowser for help on using the repository browser.