Results 1 to 7 of 7

Thread: How to get out from waitForReadyRead(Timeout) blocking?

  1. #1
    Join Date
    Jun 2008
    Posts
    18
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question How to get out from waitForReadyRead(Timeout) blocking?

    I have a client thread is blocked on QTcpSocket's waitForReadyRead(Timeout), other than receiving a message from server or reducing timeout length, how do I get out of the blocked state gracefully(basicly get out of the client waiting loop)?

    Thanks in advance.

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    Maybe you can use QIODevice::readyRead() signal instead of waitForReadyRead().

  3. #3
    Join Date
    Jun 2008
    Posts
    18
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    That's one option, but it requires a new design. I'm looking for a quick solution, if there is one

    Thanks for the reply!

  4. #4
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    What about (very quick and dirty)
    Qt Code:
    1. bool dataAvailable = false;
    2. t.start();
    3.  
    4. do
    5. {
    6. dataAvailable = waitForReadyRead(smallTimeout);
    7. QApplication::processEvents();
    8. }
    9. while(!dataAvailable && (t.elapsed() < Timeout));
    10.  
    11. if(dataAvailable)
    12. {
    13. // process your data
    14. }
    15. else
    16. {
    17. // process timeout
    18. }
    To copy to clipboard, switch view to plain text mode 

    Not a really nice way, but could work if you do not require precise timeout conditions.

  5. #5
    Join Date
    Jun 2008
    Posts
    18
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    ars,

    That's not what I wanted. I want it stays blocked waiting for data, not timed out by itself, but have an option to get out at anytime.

  6. #6
    Join Date
    Dec 2009
    Posts
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    Its either waiting or it aint, you cant have it both ways. Close the socket your waiting on.

    cheers

  7. #7
    Join Date
    Jun 2008
    Posts
    18
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get out from waitForReadyRead(Timeout) blocking?

    Look like non-blocking is the only way out. Thank you guys for the reply!

Similar Threads

  1. QextSerialPort and waitForReadyRead problem
    By Ivan Wagner in forum Qt Programming
    Replies: 12
    Last Post: 20th August 2010, 07:52
  2. qextserialport waitForReadyRead and timeOut
    By adamatic in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2009, 09:52
  3. QUdp and waitForReadyRead
    By babu198649 in forum Newbie
    Replies: 5
    Last Post: 22nd December 2008, 18:49
  4. QextSerialPort WaitForReadyRead()
    By kingslee in forum Qt Programming
    Replies: 9
    Last Post: 9th October 2008, 19:44
  5. waitForReadyRead() disconnects tcp socket?
    By pdoria in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2008, 20:49

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.