Results 1 to 3 of 3

Thread: question about socket and threads?

  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Default question about socket and threads?

    Hi,

    My program was using QT3's QSocketDevice. There are 3 threads in my program.
    The main thread first create the QSocketDevice, and connect to the host. Once connected, the main thread will not access to this QSocketDevice anymore. Then, I created one sending thread, and one receiving thread. Both sending thread and receiving thread access to the same QSocketDevice which was created by main thread.

    But, now, I tried to switch to QT4's QAbstractSocket or QTckSocket. How can I do that?

    Thread A: create socket sd and connect it to the host.
    Thread B: taking care of sending data to the host using socket sd.
    Thread C: taking care of receiving data from the host using socket sd.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: question about socket and threads?

    You can't do it this way. The socket has to be handled by the same thread (or to be more precise, by one thread at once).

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: question about socket and threads?

    however as a thread has it's own event loop you don't need to split various socket management tasks in several threads... just connect proper slots and everything will be fine
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Thread(s) and socket, timer slots
    By stephdev1965 in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2006, 14:04
  2. Organizing multiple threads
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2006, 09:53

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.