Common way to selecting correct slot
-
@SGaist Object from send signal comes to QSerialPort
@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
-
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
@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". -
@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:
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.
-
Hi, that solution is ok?
sendData & readData are connected to serial. Im not run it, just wrote fust sample#ifndef SB_H #define SB_H #include <QObject> class SerialBroadcaster : public QObject { Q_OBJECT public: explicit SerialBroadcaster(QObject *parent = nullptr); public slots: void send(const QByteArray &data, int reciver){ this->reciver = reciver; emit sendData(data); } void readData(const QByteArray &data){ if(reciver == 1) respondeToConsole(data); else if(reciver == 2) respondToCommand(data); reciver = 0; } signals: void sendData(const QByteArray &data); void respondeToConsole(const QByteArray &data); void respondToCommand(const QByteArray &data); private: int reciver = 0; }; #endif // TCPREADER_H
-
Hi, that solution is ok?
sendData & readData are connected to serial. Im not run it, just wrote fust sample#ifndef SB_H #define SB_H #include <QObject> class SerialBroadcaster : public QObject { Q_OBJECT public: explicit SerialBroadcaster(QObject *parent = nullptr); public slots: void send(const QByteArray &data, int reciver){ this->reciver = reciver; emit sendData(data); } void readData(const QByteArray &data){ if(reciver == 1) respondeToConsole(data); else if(reciver == 2) respondToCommand(data); reciver = 0; } signals: void sendData(const QByteArray &data); void respondeToConsole(const QByteArray &data); void respondToCommand(const QByteArray &data); private: int reciver = 0; }; #endif // TCPREADER_H
@qtprogrammer123 said in Common way to selecting correct slot:
Hi, that solution is ok?
sendData & readData are connected to serial. Im not run it, just wrote fust sample#ifndef SB_H #define SB_H #include <QObject> class SerialBroadcaster : public QObject { Q_OBJECT public: explicit SerialBroadcaster(QObject *parent = nullptr); public slots: void send(const QByteArray &data, int reciver){ this->reciver = reciver; emit sendData(data); } void readData(const QByteArray &data){ if(reciver == 1) respondeToConsole(data); else if(reciver == 2) respondToCommand(data); reciver = 0; } signals: void sendData(const QByteArray &data); void respondeToConsole(const QByteArray &data); void respondToCommand(const QByteArray &data); private: int reciver = 0; }; #endif // TCPREADER_H
+erros signal, and probably others that I don't think about right now