QSignalSpy: Extract connection functionality into a separate method
Change-Id: Ie6406c79b070cba715250711578cd3d80c089559 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9dc594b2bf
commit
25354bd01a
@ -59,7 +59,6 @@ public:
|
|||||||
explicit QSignalSpy(const QObject *obj, const char *aSignal)
|
explicit QSignalSpy(const QObject *obj, const char *aSignal)
|
||||||
: m_waiting(false)
|
: m_waiting(false)
|
||||||
{
|
{
|
||||||
static const int memberOffset = QObject::staticMetaObject.methodCount();
|
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
qWarning("QSignalSpy: Cannot spy on a null object");
|
qWarning("QSignalSpy: Cannot spy on a null object");
|
||||||
return;
|
return;
|
||||||
@ -83,11 +82,9 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
|
if (!connectToSignal(obj, sigIndex))
|
||||||
Qt::DirectConnection, nullptr)) {
|
|
||||||
qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
sig = ba;
|
sig = ba;
|
||||||
initArgs(mo->method(sigIndex), obj);
|
initArgs(mo->method(sigIndex), obj);
|
||||||
}
|
}
|
||||||
@ -100,7 +97,6 @@ public:
|
|||||||
QSignalSpy(const typename QtPrivate::FunctionPointer<Func>::Object *obj, Func signal0)
|
QSignalSpy(const typename QtPrivate::FunctionPointer<Func>::Object *obj, Func signal0)
|
||||||
: m_waiting(false)
|
: m_waiting(false)
|
||||||
{
|
{
|
||||||
static const int memberOffset = QObject::staticMetaObject.methodCount();
|
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
qWarning("QSignalSpy: Cannot spy on a null object");
|
qWarning("QSignalSpy: Cannot spy on a null object");
|
||||||
return;
|
return;
|
||||||
@ -121,11 +117,9 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
|
if (!connectToSignal(obj, sigIndex))
|
||||||
Qt::DirectConnection, nullptr)) {
|
|
||||||
qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
sig = signalMetaMethod.methodSignature();
|
sig = signalMetaMethod.methodSignature();
|
||||||
initArgs(mo->method(sigIndex), obj);
|
initArgs(mo->method(sigIndex), obj);
|
||||||
}
|
}
|
||||||
@ -160,6 +154,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool connectToSignal(const QObject *sender, int sigIndex)
|
||||||
|
{
|
||||||
|
static const int memberOffset = QObject::staticMetaObject.methodCount();
|
||||||
|
const bool connected = QMetaObject::connect(
|
||||||
|
sender, sigIndex, this, memberOffset, Qt::DirectConnection, nullptr);
|
||||||
|
|
||||||
|
if (!connected)
|
||||||
|
qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
|
||||||
|
|
||||||
|
return connected;
|
||||||
|
}
|
||||||
|
|
||||||
void initArgs(const QMetaMethod &member, const QObject *obj)
|
void initArgs(const QMetaMethod &member, const QObject *obj)
|
||||||
{
|
{
|
||||||
args.reserve(member.parameterCount());
|
args.reserve(member.parameterCount());
|
||||||
|
Loading…
Reference in New Issue
Block a user