diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-08 10:59:03 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-08 10:59:03 (GMT) |
commit | f64170262441cce51b52d05a2f2ba2f0021ba8e4 (patch) | |
tree | dc22f539a4474064d0604e81db7340d679063c71 | |
parent | 58bf96d7252df3346d0f325af265873897e56172 (diff) | |
download | Qt-f64170262441cce51b52d05a2f2ba2f0021ba8e4.zip Qt-f64170262441cce51b52d05a2f2ba2f0021ba8e4.tar.gz Qt-f64170262441cce51b52d05a2f2ba2f0021ba8e4.tar.bz2 |
make sure connections and event filters are removed when state machine halts
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 16 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 4 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 110a4f8..24af8e4 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1224,10 +1224,12 @@ void QStateMachinePrivate::_q_process() break; case Finished: state = NotRunning; + unregisterAllTransitions(); emit q->finished(); break; case Stopped: state = NotRunning; + unregisterAllTransitions(); emit q->stopped(); break; } @@ -1358,6 +1360,20 @@ void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transit #endif } +void QStateMachinePrivate::unregisterAllTransitions() +{ + { + QList<QSignalTransition*> transitions = qFindChildren<QSignalTransition*>(rootState); + for (int i = 0; i < transitions.size(); ++i) + unregisterSignalTransition(transitions.at(i)); + } + { + QList<QEventTransition*> transitions = qFindChildren<QEventTransition*>(rootState); + for (int i = 0; i < transitions.size(); ++i) + unregisterEventTransition(transitions.at(i)); + } +} + #ifndef QT_NO_STATEMACHINE_EVENTFILTER void QStateMachinePrivate::registerEventTransition(QEventTransition *transition) { diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index bb4a78c..47b139c 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -150,6 +150,7 @@ public: void unregisterEventTransition(QEventTransition *transition); #endif void unregisterTransition(QAbstractTransition *transition); + void unregisterAllTransitions(); void handleTransitionSignal(const QObject *sender, int signalIndex, void **args); void scheduleProcess(); diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 93cd1b3..288cbec 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1631,6 +1631,8 @@ void tst_QStateMachine::signalTransitions() emitter.emitSignalWithNoArg(); QTRY_COMPARE(finishedSpy.count(), 1); + + emitter.emitSignalWithNoArg(); } { QStateMachine machine; @@ -1722,6 +1724,8 @@ void tst_QStateMachine::eventTransitions() QCoreApplication::processEvents(); QTRY_COMPARE(finishedSpy.count(), 1); + + QTest::mousePress(&button, Qt::LeftButton); } { QStateMachine machine; |