[英]Reverse QMetaMethod::fromSignal()
We can have我们可以有
QMetaMethod::fromSignal(PointerToMemberFunction)
returning QMetaMethod返回QMetaMethod
My question is, is it possible to have something like this?我的问题是,有可能有这样的东西吗?
fromMetaMethod(QMetaMethod)
returning PointerToMemberFunction ??返回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.SIGNAL()
连接样式在您自己的 class 中创建信号到信号连接,从SomeClass::someSignal
到您自己的信号。 You only have to make sure the parameters of the original signal are forwarded to your lambda.您只需确保将原始信号的参数转发到您的 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) { ... }
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.