summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-07-03 22:13:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-10 06:20:23 +0200
commitbc5a4d28afbd273adeaae75ebd4aeb97337df6ed (patch)
tree6e1571abca3c0b5eb1f5b35b5e8c51781d32017c
parent5db78a077b8f070b6e28431de6c3add6660ad1be (diff)
Set compound state's initial state to 0 if it is removed/deleted
Change-Id: I45b7c15a9b3d5a1860cb9a7da8836f9eaaa0326d Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
-rw-r--r--src/corelib/statemachine/qstate.cpp2
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp13
2 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 14432edd7c..39651b9736 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -495,6 +495,8 @@ bool QState::event(QEvent *e)
if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) {
d->childStatesListNeedsRefresh = true;
d->transitionsListNeedsRefresh = true;
+ if ((e->type() == QEvent::ChildRemoved) && (static_cast<QChildEvent *>(e)->child() == d->initialState))
+ d->initialState = 0;
}
return QAbstractState::event(e);
}
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index 6fde415f2a..102f96b1dc 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -189,6 +189,7 @@ private slots:
void initialStateIsEnteredBeforeStartedEmitted();
void deletePropertyAssignmentObjectBeforeEntry();
void deletePropertyAssignmentObjectBeforeRestore();
+ void deleteInitialState();
};
class TestState : public QState
@@ -4073,5 +4074,17 @@ void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
delete o2;
}
+void tst_QStateMachine::deleteInitialState()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(&machine);
+ machine.setInitialState(s1);
+ delete s1;
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start: No initial state set for machine. Refusing to start.");
+ machine.start();
+ // Shouldn't crash
+ QCoreApplication::processEvents();
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"