Advanced signal/slot usage
-
Hi
Suppose I have 2 classes A and BClass B has a signal
Class A has a slot designed to handle B's signal
Now what I want to do is to arrange things such that class A connects its slot to ALL instances of B
Is it possible?Any ideas are appreciated
Thanks
-
Hi,
Is this what you want to do ?@Class A {
ClassB *b = new ClassB(this);
connect(b,SIGNAL(signalfromb()),this,SLOT(CallSlotOfA()));};
@So whenever signal gets emitted from any particular instance of B it will call class A's slot viz. CallSlotOfA().
-
[quote author="p3c0" date="1379402708"]
Is this what you want to do ?
[/quote]
i don't think so, but i may be wrong either :)If i got you right GrahamL you want to connect your signal to all current instances in the memory?
This is only possible if you have them specified as childs.Something like this:
@
A::connectAllSignalsToBInstances()
{
QList<B*> objectList = this->findChildren<B*>();
foreach( B* b, objectList )
connect(b,SIGNAL(signal()),this,SLOT(slot()));
}
@ -
Can you make a signal or a slot static? I never tried. But if you can, there might be a simple solution to this.
Another idea would be to create the connection within the constructor of B. Would that be a possibility for you?
-
[quote author="thEClaw" date="1379406246"]Can you make a signal or a slot static? I never tried. But if you can, there might be a simple solution to this.[/quote]
No that's not possible. -
Thanks everyone
I think I need to revist my design!