We can have
QMetaMethod::fromSignal(PointerToMemberFunction)
returning QMetaMethod
My question is, is it possible to have something like this?
fromMetaMethod(QMetaMethod)
returning PointerToMemberFunction ??
Thanks.
One way to create the connection you want does not require you to find any methods address.
Simply:
SomeClass::someSignal
to your own signal in your own class using the SIGNAL()
connection style.You only have to make sure the parameters of the original signal are forwarded to your lambda.
Example:
QObject::connect(
pointerToSomeClass, SIGNAL(someSignal(int)),
pointerToMyClass , SIGNAL(mySignal(int)),
Qt::DirectConnection
);
QObject::connect(
pointerToMyClass, &MyClass::mySignal,
[](int i) { ... }
);
If you happen to need the sender of the original signal, then you will need a slot.
Example:
void myClass::mySlot(int i)
{
emit mySignal(sender(), i);
}
and
QObject::connect(
pointerToSomeClass, SIGNAL(someSignal(int)),
pointerToMyClass , SIGNAL(mySlot(int)),
Qt::DirectConnection
);
QObject::connect(
pointerToMyClass, &MyClass::mySignal,
[](QObject* sender, int i) { ... }
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.