summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/statemachine/qstate.cpp5
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp28
2 files changed, 31 insertions, 2 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 5463059..ebb0b47 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -329,9 +329,10 @@ QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
qWarning("QState::addTransition: cannot add transition to null state");
return 0;
}
- if (*signal && sender->metaObject()->indexOfSignal(signal+1) == -1) {
+ int offset = (*signal == '0'+QSIGNAL_CODE) ? 1 : 0;
+ if (sender->metaObject()->indexOfSignal(signal+offset) == -1) {
qWarning("QState::addTransition: no such signal %s::%s",
- sender->metaObject()->className(), signal+1);
+ sender->metaObject()->className(), signal+offset);
return 0;
}
QSignalTransition *trans = new QSignalTransition(sender, signal, QList<QAbstractState*>() << target);
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 768a683..66e50ba 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -1768,6 +1768,34 @@ void tst_QStateMachine::signalTransitions()
QState *s0 = new QState(machine.rootState());
QFinalState *s1 = new QFinalState(machine.rootState());
SignalEmitter emitter;
+ QSignalTransition *trans = s0->addTransition(&emitter, "signalWithNoArg()", s1);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), s0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ QCOMPARE(trans->signal(), QByteArray("signalWithNoArg()"));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ trans->setSignal("signalWithIntArg(int)");
+ QCOMPARE(trans->signal(), QByteArray("signalWithIntArg(int)"));
+ machine.start();
+ QCoreApplication::processEvents();
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1);
s0->addTransition(trans);