From e72285b0108f7649366a106f1c16ea73611dbcd4 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 3 Jun 2009 13:17:37 +0200 Subject: don't require use of SIGNAL macro in calls to addTransition() Just as with the QSignalTransition::signal property, this makes it possible to use the function from language bindings (e.g. QtScript). --- src/corelib/statemachine/qstate.cpp | 5 +++-- tests/auto/qstatemachine/tst_qstatemachine.cpp | 28 ++++++++++++++++++++++++++ 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() << 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); -- cgit v0.12