diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp index 7ec72df77c..e8c5f3e479 100644 --- a/src/corelib/statemachine/qsignaltransition.cpp +++ b/src/corelib/statemachine/qsignaltransition.cpp @@ -145,6 +145,19 @@ QSignalTransition::QSignalTransition(const QObject *sender, const char *signal, d->maybeRegister(); } +/*! + \fn QSignalTransition::QSignalTransition(const QObject *sender, + PointerToMemberFunction signal, QState *sourceState); + \since 5.7 + \overload + + Constructs a new signal transition associated with the given \a signal of + the given \a sender object and with the given \a sourceSate. + This constructor is enabled if compiler supports delegating constructor. + + \sa Q_COMPILER_DELEGATING_CONSTRUCTORS +*/ + /*! Destroys this signal transition. */ diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h index c388323ec4..b428cb621d 100644 --- a/src/corelib/statemachine/qsignaltransition.h +++ b/src/corelib/statemachine/qsignaltransition.h @@ -35,6 +35,7 @@ #define QSIGNALTRANSITION_H #include +#include QT_BEGIN_NAMESPACE @@ -52,6 +53,18 @@ public: QSignalTransition(QState *sourceState = Q_NULLPTR); QSignalTransition(const QObject *sender, const char *signal, QState *sourceState = Q_NULLPTR); +#ifdef Q_QDOC + QSignalTransition(const QObject *object, PointerToMemberFunction signal, + QState *sourceState = Q_NULLPTR); +#elif defined(Q_COMPILER_DELEGATING_CONSTRUCTORS) + template + QSignalTransition(const typename QtPrivate::FunctionPointer::Object *obj, + Func sig, QState *srcState = Q_NULLPTR) + : QSignalTransition(obj, QMetaMethod::fromSignal(sig).methodSignature().constData(), srcState) + { + } +#endif + ~QSignalTransition(); QObject *senderObject() const; diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 1ae4057049..379215a6c5 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -238,6 +238,9 @@ private slots: void multiTargetTransitionInsideParallelStateGroup(); void signalTransitionNormalizeSignature(); +#ifdef Q_COMPILER_DELEGATING_CONSTRUCTORS + void createPointerToMemberSignalTransition(); +#endif void createSignalTransitionWhenRunning(); void createEventTransitionWhenRunning(); void signalTransitionSenderInDifferentThread(); @@ -5876,6 +5879,31 @@ void tst_QStateMachine::signalTransitionNormalizeSignature() TEST_ACTIVE_CHANGED(s1, 1); } +#ifdef Q_COMPILER_DELEGATING_CONSTRUCTORS +void tst_QStateMachine::createPointerToMemberSignalTransition() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + DEFINE_ACTIVE_SPY(s1); + machine.setInitialState(s1); + machine.start(); + TEST_ACTIVE_CHANGED(s1, 1); + QTRY_VERIFY(machine.configuration().contains(s1)); + + QState *s2 = new QState(&machine); + DEFINE_ACTIVE_SPY(s2); + SignalEmitter emitter; + QSignalTransition *t1 = new QSignalTransition(&emitter, &SignalEmitter::signalWithNoArg, s1); + QCOMPARE(t1->sourceState(), s1); + t1->setTargetState(s2); + s1->addTransition(t1); + emitter.emitSignalWithNoArg(); + TEST_ACTIVE_CHANGED(s1, 2); + TEST_ACTIVE_CHANGED(s2, 1); + QTRY_VERIFY(machine.configuration().contains(s2)); +} +#endif + void tst_QStateMachine::createSignalTransitionWhenRunning() { QStateMachine machine;