You can identify the socket which sent the signal by calling QObject::sender() in the slot. Just be aware that the sender is undefined if the slot is called as a normal C++ function.
You can identify the socket which sent the signal by calling QObject::sender() in the slot. Just be aware that the sender is undefined if the slot is called as a normal C++ function.
J-P Nurmi
thanks jpn,
i can get a refrence using QObject::sender() but i am still not able to catch the point.
What i will get i s a QObject *ptrof sender. I read the doc but i couldn't figure out what characterstic of it wil be useful to me.
situation is like this. I have multiple algo writing data to their socket . A server which listen to these socket on readyRead() signal read from the socket. Now till now my code was for one client only. Now i wan to make it for multiple clients. So i have to keep track of data send by which socket and store their history( previous send data) also. Thats why i am looking for diferentiation between received data.
ALso next issue come when i am making a list of list of received data. One list for each socket. How i will address or index them. Like i am creating a list whenever a new connection appears and append that to main list. But when next piece of data comes how i am going to decide which list i am going to use for storage. These are major issues form e currently.
Is the way i am addressing this problem correct. Seond method which i am avoiding is creation of a thread for each new connection. and when socket exit i copy all data at one place.
You should cast the QObject pointer to an appropriate type.
Eg.
Qt Code:
if (socket) { // do something }To copy to clipboard, switch view to plain text mode
And how about something like this for the data storage:
Qt Code:
QHash<int, HistoryData> // where int is QTcpSocket::socketDescriptor() // and HistoryData is any storage you decide to use, eg. QStringListTo copy to clipboard, switch view to plain text mode
J-P Nurmi
quickNitin (4th July 2006)
Bookmarks