summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasaru Ueki <masaru.ueki@itage.co.jp>2015-12-26 16:01:25 +0900
committerMasaru Ueki <masaru.ueki@itage.co.jp>2016-01-05 10:05:40 +0000
commite0a5f661e52fd09611f406ae82128b6ef81fe90e (patch)
tree435968454e360fe7e3bbc1b419893bba51530994
parent38c8af7231823429ca6cb9ea6418e2dcef3691a0 (diff)
QStateMachine: fix ignore high-priority events.
When a high-priority event is posted in overrided 'QStateMachine::beginSelectTransitions', the event may be remained in event queue, and be not dispatched until another event posted. Change-Id: Ifda288d9c00ac7985e426b9cc02bda382ebaac35 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp10
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp29
2 files changed, 35 insertions, 4 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index e5d019dc8b..ee522218ee 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1946,12 +1946,14 @@ void QStateMachinePrivate::_q_process()
}
}
if (enabledTransitions.isEmpty()) {
- processing = false;
- stopProcessingReason = EventQueueEmpty;
- noMicrostep();
+ if (isInternalEventQueueEmpty()) {
+ processing = false;
+ stopProcessingReason = EventQueueEmpty;
+ noMicrostep();
#ifdef QSTATEMACHINE_DEBUG
- qDebug() << q << ": no transitions enabled";
+ qDebug() << q << ": no transitions enabled";
#endif
+ }
} else {
didChange = true;
q->beginMicrostep(e);
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index 1292c3b98f..e60b1c983c 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -250,6 +250,7 @@ private slots:
void internalTransition();
void conflictingTransition();
void qtbug_46059();
+ void postEventFromBeginSelectTransitions();
};
class TestState : public QState
@@ -6485,5 +6486,33 @@ void tst_QStateMachine::qtbug_46059()
QVERIFY(machine.isRunning());
}
+void tst_QStateMachine::postEventFromBeginSelectTransitions()
+{
+ class StateMachine : public QStateMachine {
+ protected:
+ void beginSelectTransitions(QEvent* e) Q_DECL_OVERRIDE {
+ if (e->type() == QEvent::Type(QEvent::User + 2))
+ postEvent(new QEvent(QEvent::Type(QEvent::User + 1)), QStateMachine::HighPriority);
+ }
+ } machine;
+ QState a(&machine);
+ QState success(&machine);
+
+ machine.setInitialState(&a);
+ a.addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), &success));
+
+ machine.start();
+
+ QTRY_COMPARE(machine.configuration().contains(&a), true);
+ QTRY_COMPARE(machine.configuration().contains(&success), false);
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 2)), QStateMachine::NormalPriority);
+
+ QTRY_COMPARE(machine.configuration().contains(&a), false);
+ QTRY_COMPARE(machine.configuration().contains(&success), true);
+
+ QVERIFY(machine.isRunning());
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"