Results 1 to 5 of 5

Thread: TcpSocket and QTextStream does not print first line of data

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default TcpSocket and QTextStream does not print first line of data

    I have the following function:

    Qt Code:
    1. void Rsh::receiveMessage() {
    2.  
    3. QString responseLine;
    4. QString response;
    5.  
    6. QTextStream in(tcpSocket);
    7.  
    8. if( !tcpSocket->canReadLine() )
    9. {
    10. return;
    11. }
    12.  
    13. while( tcpSocket->canReadLine() ){
    14. responseLine = tcpSocket->readLine();
    15. response.append(responseLine);
    16. }
    17. ui.ResultsTextEdit->append(tr("%1").arg(response));
    18. }
    To copy to clipboard, switch view to plain text mode 

    This works to pull data from the connection, however the first complete line of text is always missing...

    any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: TcpSocket and QTextStream does not print first line of data

    Where do you use "in"?

  3. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: TcpSocket and QTextStream does not print first line of data

    Thats the only one....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: TcpSocket and QTextStream does not print first line of data

    Quote Originally Posted by nbkhwjm View Post
    Thats the only one....
    Could you elaborate? You create QTextStream instance and never use it and most likely that's what eats your first line.

  5. The following user says thank you to jacek for this useful post:

    nbkhwjm (8th January 2008)

  6. #5
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: TcpSocket and QTextStream does not print first line of data

    You are correct... The first line was in the "in" buffer.... while i was only printing the "response".

    This seems to work fine...

    Thanks for the pointer.

    Qt Code:
    1. void Rsh::receiveMessage() {
    2.  
    3. QString responseLine;
    4. QString response;
    5.  
    6. QTextStream in(tcpSocket);
    7.  
    8. if( !tcpSocket->canReadLine() )
    9. {
    10. return;
    11. }
    12.  
    13. while( tcpSocket->canReadLine() ){
    14. responseLine = in.readAll();
    15. response.append(responseLine);
    16. }
    17. ui.ResultsTextEdit->append(response);
    18. }
    To copy to clipboard, switch view to plain text mode 

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.