Wrapping brain around SIGNALS
-
I have a class A with signal sendRequest(somepayload * payload)
I have a class B with slot OnRequest(somepayload * payload)I connect the two with QObject::connect..
In class B i implement a slot for "somepayload".
But in class A, what do I do? other methods in A call "emit(this->somepayload(payload))" but all I really want is for "OnRequest" to be called in class B with my payload.
What do I implement in class A? It seems I have to "implement" the signal, but what exactly should I do there? it doesn't make sense. Can I leave it empty?
-
Nothing to do. You must not implement a signal yourself. Just declare it in the header file under the signals keyword.
Behind the scenes, it is a regular C++ method, but the actual implementation is provided by Qt (this is one of the points where moc enters the game).
Just call "emit sendRequest(myPayload)", that's all.
If your class A knows of class B, and if you have a B object, you can call B's slot directly too. Your two classes are then coupled tightly.