From edb8bac39b9e7c16925aa0762bbf7feaf6f552ab Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 19 Mar 2024 09:03:31 +0100 Subject: [PATCH] QSignalSpy: Extract Method init() from three ctors Ideally, this wouldn't be a named function, but a delegatee constructor, but the current structure of the three constructors doesn't, yet, lend itself to extracting a delegatee constructor (the tail is copied, not the head). To get there, we need more work (coming up in follow-up commits). Task-number: QTBUG-123544 Change-Id: I46dd030e314d67c2ab624279d669db76e58bc569 Reviewed-by: David Faure --- src/testlib/qsignalspy.h | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h index 1b67225b50b..75e2668de22 100644 --- a/src/testlib/qsignalspy.h +++ b/src/testlib/qsignalspy.h @@ -43,11 +43,7 @@ public: return; } - initArgs(mo->method(sigIndex), obj); - if (!connectToSignal(obj, sigIndex)) - return; - - sig = ba; + init(obj, mo->method(sigIndex)); } #ifdef Q_QDOC @@ -65,30 +61,15 @@ public: return; } - const QMetaObject * const mo = obj->metaObject(); const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal0); - const int sigIndex = signalMetaMethod.methodIndex(); - - if (!isSignalMetaMethodValid(signalMetaMethod)) - return; - - initArgs(mo->method(sigIndex), obj); - if (!connectToSignal(obj, sigIndex)) - return; - - sig = signalMetaMethod.methodSignature(); + init(obj, signalMetaMethod); } #endif // Q_QDOC QSignalSpy(const QObject *obj, QMetaMethod signal) { - if (isObjectValid(obj) && isSignalMetaMethodValid(signal)) { - initArgs(signal, obj); - if (!connectToSignal(obj, signal.methodIndex())) - return; - - sig = signal.methodSignature(); - } + if (isObjectValid(obj)) + init(obj, signal); } inline bool isValid() const { return !sig.isEmpty(); } @@ -128,6 +109,18 @@ public: } private: + void init(const QObject *obj, QMetaMethod signal) + { + if (!isSignalMetaMethodValid(signal)) + return; + + initArgs(signal, obj); + if (!connectToSignal(obj, signal.methodIndex())) + return; + + sig = signal.methodSignature(); + } + bool connectToSignal(const QObject *sender, int sigIndex) { static const int memberOffset = QObject::staticMetaObject.methodCount();