Results 1 to 11 of 11

Thread: readLine problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: readLine problem

    Quote Originally Posted by gQt View Post
    Thanks for your reply!

    I have tested that the data is available with the telnet command. The data comes with both LF and CR so canReadline /readLine should work. Output to terminal looks like this (changed all of the couts to english now)
    Does the output come to the terminal within a 1ns after establishing the connection? I doubt that... The data arrives, but it arrives later - you can't connect and expect the data to be already there.

  2. #2
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: readLine problem

    I'm doing an if (waitForConnected(-1)) after the connectToHost if that wat you mean?

    Should I add anything else here?
    (I'm new to Qt and Socket-programming)

    From the read_data() function:

    Qt Code:
    1. tcpSocket->abort();
    2. tcpSocket->connectToHost(hostLineEdit->text(),
    3. portLineEdit->text().toInt());
    4.  
    5. cout << ("after connectToHost\n");
    6.  
    7. if(tcpSocket->waitForConnected(-1))
    8. {
    9. cout <<"wait for connected loop\n";
    10. if(tcpSocket->canReadLine())
    11. {
    12. mystring=tcpSocket->readLine();
    13. qDebug() << "READ" << mystring;
    14. cout <<"canReadLine loop after readLine\n";
    15. }
    16. statusLabel->setText(mystring);
    17. getFortuneButton->setEnabled(false);
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 27th February 2008 at 13:13. Reason: missing [code] tags

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

    Default Re: readLine problem

    Quote Originally Posted by gQt View Post
    I'm doing an if (waitForConnected(-1)) after the connectToHost if that wat you mean?
    No, this waits for the connection to be established, not for the data to be ready.

    Should I add anything else here?
    QAbstractSocket::waitForReadyRead
    (I'm new to Qt and Socket-programming)
    That should motivate you to do some more reading.

  4. #4
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: readLine problem

    Thanks a mill wysota !
    I hadn't thought about the waitForReadyRead- that I had to wait for the data to be ready to read also.

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

    Default Re: readLine problem

    Be aware that the fact that waitForReadyRead returns means there is something to read, not that everything is ready to be read.

  6. The following user says thank you to wysota for this useful post:

    gQt (29th February 2008)

Similar Threads

  1. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. QTextStream, input and readLine()
    By kramed in forum Newbie
    Replies: 6
    Last Post: 1st September 2007, 23:54
  4. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.