Results 1 to 7 of 7

Thread: thread with socket?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: thread with socket?

    Quote Originally Posted by yuriry View Post
    You would only need to call it if you wanted to use sockets in a non-blocking way on a separate thread.
    yeah thats what i need.. so i will add exec() then?

    i will just call it pass some parameter and execute, I dont need the return data i dont even need to test if the socket connects or not I want to let the thread do that and the application do what it should do.. Calling the socket blocks the GUI so i put it in a thread but if i need to put thread->wait() it will block GUI too..

    im just avoiding to call it as binary but if it will block the GUI then i will reconsider it..

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: thread with socket?

    Use QSocketNotifier.
    No need to create a separate thread. (You still may to so, if you want, though.)

    HTH

  3. #3
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: thread with socket?

    yeah thats what i need.. so i will add exec() then?
    exec() is only required if you want to start an event loop on a thread. If you used QTcpSocket in conjunction with readyRead signal then you would need an event loop. But if you use Linux sockets, and I assume you do NOT use select/poll, just read/write, then you use them in a blocking fashion and your code should be similar to this example http://doc.trolltech.com/4.4/network...uneclient.html Even if sockets are used there in a blocking way, GUI thread does not block because blocking read/write calls occur on a separate thread.

    And as caduel pointed out, there is a way to achieve non-blocking behavior without creating extra threads, but it seems that it is not an option for you because you are just integrating existing code and do not want to do many changes to it.

Similar Threads

  1. Socket on a Thread
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2008, 15:56
  2. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  3. socket in thread error!
    By alphaboy in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2007, 12:15
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. How to write on a socket in another thread?
    By Valheru in forum Qt Programming
    Replies: 7
    Last Post: 12th October 2006, 10:52

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.