Slots and signals problem
-
Hello,
I have a Terminal class, which is the controller for my application.
The controller has two objects in it.
-
Ink
-
Laser
-
Ink.Start();
-
Laser.Start();
When the Ink is ready, it must send a ready message to the controller
When the Laser is ready, it must send a ready message to the controllerAnd the laser should communicate the status to Ink and vice versa.
How should I implement this? Can someone give me an example. Many thanks in advance. -
-
Thanks for the support.
Question answered, connection is made via connect.
-
hi
what do you mean by "terminal class" ? is this a console app ? or anything completely different ?
in most cases you would do insert this code in Controller class, after both components have been instanciated, assuming that the signal in Ink class is named ready
connect (pointer_to_ink, &Ink::ready, this, &Controller::correspondingSlot)
for comunication between Ink and Laser, depends on how you want to achieve it. If you want a direct connection then you use similar syntax. Still in Controller class
connect (pointer_to_ink, &Ink::ready, pointer_to_laser, &Laser::correspondingSlot)
if you want to transmit signals between the two components by intermediate of the controller (aka mediator pattern), then you need to define signals in the controller class and connect signal to signal
// Still within Controller class after instanciation of both ink and laser connect (pointer_to_ink, &Ink::ready, this, &Controller::inkReady) ; // Yes Controller::inkReady as a signal, signal to signal connection connect (this, &Controller::inkReady, pointer_to_laser, &Laser::inkReady)
@RobertSommer said in Slots and signals problem:
And the laser should communicate the status to Ink and vice versa.
It is generally unadviced that two classes have mutual knowledge of each other, circular dependencies may be the cause of lots of problems and avoiding them is generally a good thing. If you have a controller to manage them both, you shouldn't have a need for that mutual knowledge.
Looks like it's a laser printer related stuff and I see no reason for the ink stuff to have knowledge about laser and conversely. Only controller should know about both. -
I am not sure if the complexity of mediator class is needed here...
Best to start reading about signals and slots in our documentation. -
I agree, I'm not really sure either it's needed. if it's just to connect signals and slots between just two components yeah it's overkill.
but the fact that OP wants both components to communicate with controller and also with each other ... assuming that there are only those two inner components ... that's what raising some "suspicions" to me. -
I agree, I'm not really sure either it's needed. if it's just to connect signals and slots between just two components yeah it's overkill.
but the fact that OP wants both components to communicate with controller and also with each other ... assuming that there are only those two inner components ... that's what raising some "suspicions" to me.@CassD said in Slots and signals problem:
the fact that OP wants both components to communicate with controller and also with each other
That's already a design flaw... sure OP can do it, but for that you don't need a controller :)
To keep the controller approach, both should send updates to the controller while it delegates commands/updates further on to the right place. -
Thanks for the support.
Question answered, connection is made via connect.
-