summaryrefslogtreecommitdiffstats
path: root/examples/statemachine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-04-22 15:20:19 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-04-22 15:20:19 (GMT)
commitf87641584424deed25e2abdadea08c3be94b9ce1 (patch)
treea185687744e724a8db896970416f23d20f5cad38 /examples/statemachine
parent31f5348ea1691a7664b6abc04cf425dd02637b33 (diff)
downloadQt-f87641584424deed25e2abdadea08c3be94b9ce1.zip
Qt-f87641584424deed25e2abdadea08c3be94b9ce1.tar.gz
Qt-f87641584424deed25e2abdadea08c3be94b9ce1.tar.bz2
kill the stateactions api
It just didn't give us that much. Typically you just reimplement onEntry/onExit/onTransition when you want to do something. We go back to the signals-and-slots approach: states have entered() and exited() signals that you can connect to. It's still possible to have an action-based API, but then you build it on top of the core API, which is OK. Replacing 4 public classes (and one layer in the hierarchy) with 2 signals feels good.
Diffstat (limited to 'examples/statemachine')
-rw-r--r--examples/statemachine/composition/main.cpp4
-rw-r--r--examples/statemachine/trafficlight/main.cpp6
2 files changed, 5 insertions, 5 deletions
diff --git a/examples/statemachine/composition/main.cpp b/examples/statemachine/composition/main.cpp
index 24b823c..927fc62 100644
--- a/examples/statemachine/composition/main.cpp
+++ b/examples/statemachine/composition/main.cpp
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
s1_timer->setObjectName("s1_timer");
QTimer t1;
t1.setInterval(2000);
- s1_timer->invokeMethodOnEntry(&t1, "start");
+ QObject::connect(s1_timer, SIGNAL(entered()), &t1, SLOT(start()));
QFinalState *s1_done = new QFinalState(s1);
s1_done->setObjectName("s1_done");
s1_timer->addTransition(&t1, SIGNAL(timeout()), s1_done);
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
s2_timer->setObjectName("s2_timer");
QTimer t2;
t2.setInterval(2000);
- s2_timer->invokeMethodOnEntry(&t2, "start");
+ QObject::connect(s2_timer, SIGNAL(entered()), &t2, SLOT(start()));
QFinalState *s2_done = new QFinalState(s2);
s2_done->setObjectName("s2_done");
s2_timer->addTransition(&t2, SIGNAL(timeout()), s2_done);
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
index 528ed00..115ecad 100644
--- a/examples/statemachine/trafficlight/main.cpp
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -97,9 +97,9 @@ public:
timer->setInterval(duration);
timer->setSingleShot(true);
QState *timing = new QState(this);
- timing->invokeMethodOnEntry(light, "turnOn");
- timing->invokeMethodOnEntry(timer, "start");
- timing->invokeMethodOnExit(light, "turnOff");
+ QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
+ QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
QFinalState *done = new QFinalState(this);
timing->addTransition(timer, SIGNAL(timeout()), done);
setInitialState(timing);