
Originally Posted by
Thoosle
What I don't see is how "emit" could be used to emit to a particular widget.
It can't be used this way directly. Signals are public.
From what I'm reading in the docs, it seems like there really isn't a way to place the burdon on the "emitter" to send things only to one target. Instead, when it emits it emits to all targets(widgets) and it's the widgets responsibility to decide if the message is meant for it?
Correct. You can help yourself by using a QSignalMapper
But, I don't want to send a message to a widget that it wasn't intended for.
Don't use signals and slots then. Just register objects in the "emitter" and call its methods directly from the emitter.
My conundrum is that I don't see how to use signals/slots "connect" and/or "emit" syntax to do this????
You don't have to force using signals and slots everywhere
Emitter emitter;
Receiver rcv1, rcv2, rcv3;
emitter.register(&rcv1);
emitter.register(&rcv2);
emitter.register(&rcv3);
//...
void Emitter
::emitMessage(int id,
const QString &msg
){ Receiver *rcv = _registered[id]; // QMap<int, Receiver*>
rcv->receive(msg);
}
Emitter emitter;
Receiver rcv1, rcv2, rcv3;
emitter.register(&rcv1);
emitter.register(&rcv2);
emitter.register(&rcv3);
//...
void Emitter::emitMessage(int id, const QString &msg){
Receiver *rcv = _registered[id]; // QMap<int, Receiver*>
rcv->receive(msg);
}
To copy to clipboard, switch view to plain text mode
Bookmarks