QTcpSocket readyRead destination
-
Hi,
i'm using single instance of QTcpSocket in class but im doing two operation on it - do i need to switch connected slot every operation / use two socket instance? Or its some easier way for it? -
I got one instance of QTcpSocket in class
private: QTcpSocket *m_socket
i need to revice readyRead and select reciving slot - got two of them
void readProgress(); void readStatus();
with slot i needed depends from operation im doing reading progress or reading status.
-
@qtprogrammer123
Your question is not clear. What "two operations" are you doing on on aQTcpSocket
instance? Why are you thinking of switching connected slots? Something sounds wrong here. -
I got one instance of QTcpSocket in class
private: QTcpSocket *m_socket
i need to revice readyRead and select reciving slot - got two of them
void readProgress(); void readStatus();
with slot i needed depends from operation im doing reading progress or reading status.
-
@qtprogrammer123
I suggest you probably want to have just oneonReadyRead()
slot always attached to the socket. What you do from there, e.g. callreadProgress()
orreadStatus()
is up to you. You can maintain state as to where you got to for deciding which to call if you wish.You could alternate which slot you attach if you wish, but that requires disconnecting the previous one each time.
But be careful:
readyRead()
signal can be issued on either "partial" reads or "multiple reads". You may have to handle insufficient data received in one call as well as too much data. That will require a buffer to keep track. That's is why I'm thinking it may be easier to manage with a single slot so that the buffering can be handled in one place.If you know exactly what data your various states expect you might find
QDataSteam
transactions on the socket helpful, e.g. example https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application. -
Q qtprogrammer123 has marked this topic as solved on