View Full Version : Signals and Slots management

8th December 2011, 12:57

i am currently writing a software which has 2 classes "Robot" and "Camera" each of them represent a real physical devices, i control them each of them with through their own QTcpSocket connection. For example:
The Robot accepts a set of predefined commands like:
command: "SetJointsPositiona1 a2 ..a6" returns "true/false"
command: "GetJointsPosition" returns "a1 .. a6"
And many many more.
So since every Response must be handeled differently i have to create for each Command response an own slot. From my MainWindow (where the classes are defined) i emit a signal with "SetJointsPosition..." -> The Robot has a Slot: onSetJointsPositionSlot(QString) where the command is sent to the device. After receiving the answer the robot emits GotJointsPositionSignal(QString) which is connected to the GotJointsPositionSlot(Qstring) in Mainwindow.

But now come another two classes "Calibration" and "FollowMe".
In "Calibration" i send a signal to the robot to take some position, after the position is taken i send a signal to camera to check if the position is visible. If it is visible i send again a signal to the camera to acquire the position from camera perspective, and then back to the robot to acquire its position. And i repeat it for like 10 times. The thing is the command sent to the "Robot" or "Camera"

So you can see that the number of Signals and Slots that i have to write is enormous.

So here comes my question. How anyone manage this big number of Signals/Slots? How do you handle this kind of class-communication?


8th December 2011, 13:54

why do you use signals/slots at all? Can't you implement your functionality directly using methods? E.g. you could call "onSetJointsPositionSlot" directly. This method could return the QString that is currently emitted by a signal.


8th December 2011, 14:09
well i have reduced many of the functionalities to normal methods, but still many things just must be implemented using signals/slots (and still there are many of them) , for example when executing "FollowMe". the princip is: I hold i marker which is detected by the camera, this position is transformed to Robots position which he then takes. The Camera works like 50frame/s and each time a signal(QMatrix4x4) is sent to the Robot. but the robot must go to the new position after he already taken the old one. And this can take some time. The second thing is that while running FollowMe i should be able to do other actions like: set the speed of the robots joints or switch between follow types(orientation,translation,both) etc..
So for the robot command like "SetJointsPosition" and its return i have to implement 3 Slots, and emit 3 signals . SetJointsPositionFromMainWindow, SetJointsPositionFromCalibration, SetJointsPositionFromFollowMe. eventhough it is the same code that is executed.