Solved How to implement method, that receives object and slot of any given class?
-
Inside my class I'd like to implement such method that receives object and slot of any given class and makes connection for that slot. For example:
void Emitter::emitToSlot(receiver, Receiver::slot) { connect(this, &Emitter::signal, receiver, slot); } Emitter myEmitter; Receiver myReceiver; myEmitter.emitToSlot(&myReceiver, &Receiver::mySlot);
I tried something like this:
template<typename Func2> void Emitter::emitToSlot(const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
but this method only works inside Emitter class for Emitter slots.
-
Just moved definition in header file and it worked.
-
Why do you want to do this? It's basically just a wrapper around QObject::connect().
-
@Christian-Ehrlicher said in How to implement method, that receives object and slot of any given class?:
Why do you want to do this? It's basically just a wrapper around QObject::connect().
Let's say I have my reasons. Although I understand that it looks strange.
-
Then you have to reimplement what QObject::connect() does.
-
Just moved definition in header file and it worked.