Results 1 to 4 of 4

Thread: Also i need more guidance on issue of differentiating data read from different socket

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Also i need more guidance on issue of differentiating data read from different so

    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

  2. #2
    Join Date
    Apr 2006
    Posts
    122
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    18

    Default Re: Also i need more guidance on issue of differentiating data read from different so

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Also i need more guidance on issue of differentiating data read from different so

    You should cast the QObject pointer to an appropriate type.
    Eg.
    Qt Code:
    1. QTcpSocket* socket = dynamic_cast<QTcpSocket*>(sender());
    2. if (socket)
    3. {
    4. // do something
    5. }
    To copy to clipboard, switch view to plain text mode 

    And how about something like this for the data storage:
    Qt Code:
    1. QHash<int, HistoryData>
    2. // where int is QTcpSocket::socketDescriptor()
    3. // and HistoryData is any storage you decide to use, eg. QStringList
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    quickNitin (4th July 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.