Valheru
15th September 2006, 09:49
The problem is that my run function is returning only the first few characters (up until the first whitespace actually) of the data that has arrived on the socket. So it returns
200
instead of
200 newsreader2.eweka.nl NNRP Service Ready - news.eweka.nl (posting ok)
Anyone know why? It works fine if I uncomment the readLine() function, but I'm trying to get it to work using a datastream.
void Connection::run()
{
QTcpSocket socket;
const int Timeout = timeout * 1000;
emit emitData( "run() commencing" );
quit = false;
socket.connectToHost( hostName, port );
if( !socket.waitForConnected( Timeout ) ){
emit emitData( "returning ( socket.waitForConnected )" );
return;
}
while(!quit){
emit emitData( "entering loop" );
if( !socket.waitForReadyRead( Timeout ) ){
emit emitData( "returning ( socket.waitForReadyRead )" );
return;
}
QString data;
QTextStream dataStream( &socket );
// while( socket.canReadLine() ){
// emit emitData( socket.readLine() );
// emit emitData( QString::number( socket.bytesAvailable() ) );
// if( socket.waitForReadyRead( Timeout ) ){
// emit emitData( "returning ( socket.bytesAvailable )" );
// return;
// }
// }
dataStream >> data;
emit emitData( data );
}
}
200
instead of
200 newsreader2.eweka.nl NNRP Service Ready - news.eweka.nl (posting ok)
Anyone know why? It works fine if I uncomment the readLine() function, but I'm trying to get it to work using a datastream.
void Connection::run()
{
QTcpSocket socket;
const int Timeout = timeout * 1000;
emit emitData( "run() commencing" );
quit = false;
socket.connectToHost( hostName, port );
if( !socket.waitForConnected( Timeout ) ){
emit emitData( "returning ( socket.waitForConnected )" );
return;
}
while(!quit){
emit emitData( "entering loop" );
if( !socket.waitForReadyRead( Timeout ) ){
emit emitData( "returning ( socket.waitForReadyRead )" );
return;
}
QString data;
QTextStream dataStream( &socket );
// while( socket.canReadLine() ){
// emit emitData( socket.readLine() );
// emit emitData( QString::number( socket.bytesAvailable() ) );
// if( socket.waitForReadyRead( Timeout ) ){
// emit emitData( "returning ( socket.bytesAvailable )" );
// return;
// }
// }
dataStream >> data;
emit emitData( data );
}
}