PDA

View Full Version : TcpSocket and QTextStream does not print first line of data



nbkhwjm
8th January 2008, 17:32
I have the following function:


void Rsh::receiveMessage() {

QString responseLine;
QString response;

QTextStream in(tcpSocket);

if( !tcpSocket->canReadLine() )
{
return;
}

while( tcpSocket->canReadLine() ){
responseLine = tcpSocket->readLine();
response.append(responseLine);
}
ui.ResultsTextEdit->append(tr("%1").arg(response));
}


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

any ideas?

jacek
8th January 2008, 17:43
Where do you use "in"?

nbkhwjm
8th January 2008, 17:54
Thats the only one....

jacek
8th January 2008, 18:33
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.

nbkhwjm
8th January 2008, 18:41
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.



void Rsh::receiveMessage() {

QString responseLine;
QString response;

QTextStream in(tcpSocket);

if( !tcpSocket->canReadLine() )
{
return;
}

while( tcpSocket->canReadLine() ){
responseLine = in.readAll();
response.append(responseLine);
}
ui.ResultsTextEdit->append(response);
}