Common way to selecting correct slot
-
Hi, what is most common way to selecting correct slot, when one signal is connected with more than one? I think about something like reciving data -> selecting reciving slot(same args, similar data)
-
Hi,
Slots are not selected. Either you connect to one or not.
Note that I am not completely sure about what you are asking.
-
after someSignal emitted. I just asking about way to select only one slot, data are similar
QObject::connect(&signalSender, &signalSender::someSignal, &signalReciver1, &signalReciver::recive1); QObject::connect(&signalSender, &signalSender::someSignal, &signalReciver2, &signalReciver::recive2);
-
Disconnect the slots you don't want to get activated. But that's a pretty strange requirement.
-
ou i forgot
before this recivereciver1 / reciver2 send signal to signalSender
-
I thought its a common situation - sharing serial between 2 objects or something similar.
-
So you have one serial port that receives data that you want to dispatch to two different classes ?
What is the deciding factor to know to which of these class the data should be sent ?
-
@qtprogrammer123 said in Common way to selecting correct slot:
after someSignal emitted. I just asking about way to select only one slot, data are similar
This question is the same as "how to decide which function (not) to call." It doesn't make any sense in the general case because any function might be useful in some program. It's hard to be more specific than to say only call the functions that are useful for what you are doing. Or only connect the slots that are useful for what you are doing.
Without zooming-out and explaining what you are actually doing, it's hard to imagine the actual problem you are working on. Why do you only want one slot to be triggered? And if you only want one slot triggered, why did you connect the signal to two slots? You have a design problem somewhere else, before what you are asking about.
-
@qtprogrammer123 said in Common way to selecting correct slot:
@SGaist Object from send signal comes to QSerialPort
Sorry but that is not really clear.
Please explain how things are working in your application with regard to the serial port and in which direction.
-
To QObject can send signal with data to QSerialPort, after serial port get respond from outside, he send readyread, so how i should check in with object i should process this data
-
Do you have any identification associated with the answer ?
-
no, some values can be even respond for both slots.
soo sometimes slot1 or slot2 can recive "text" or something
-
Do you have any control on the devices connected to the serial port ?
-
Yes - im sending him command first - he only anserw, it's sync communication
-
I can make broadcasting object with reciver selecting flag ofc, but i thought its common problem
-
@qtprogrammer123 said in Common way to selecting correct slot:
To QObject can send signal with data to QSerialPort, after serial port get respond from outside, he send readyread, so how i should check in with object i should process this data
I am not sure to understand your use case.
Let me summarize what I believe you want to do:- you have a class which handles communication with a device via QSerialPort
- you want other classes to send commands to device via the communication class and then get reply
Is this correct?
If this is the use case then using signal/slot is not the best way to do it.
I would use a "exchange object" which:- store the serial command to be send
- stores the reply
- have a signal to inform about transfer state
The "sender" class will create an instance of exchange object and setup command to be send, and connect to "status" signal.
Then the "exchange object" instance will be sent to communication class, which will:- send to command to device
- store reply in exchange object
- emit status change from exchange instance.
-
@KroMignon said in Common way to selecting correct slot:
sender
both senders make own exchange object? Or its one for both senders?
-
@qtprogrammer123 said in Common way to selecting correct slot:
no, some values can be even respond for both slots.
This makes no sense.
Forget about serial communication , SIGNAL and SLOT , which objects are involved etc.How can your select correct destination of the data if you have no info what the data is ?
Most "common " way would be to analyze the data , generate (emit) desired SIGNAL and then have "connect" to pass the data to SINGLE destination .
Or generate (emit) multiple SiGNAL and have multiple "connect". -
@qtprogrammer123 said in Common way to selecting correct slot:
both senders make own exchange object? Or its one for both senders?
Again, I don't really understand your use case and I only give my interpretation.
My suggestion is to use an object between the sender(s) instance and the "serial port manager".
Something like the mechanism used byQNetworkAccessManager
withQNetworkReply
.But, it depends on what your use case is.