I suggest you change your code to non-blocking approach, then it's much easier:
void Sth::onReadyRead(){
while(socket.canReadLine()){
s = ts.readLine();
}
}
QTextStream ts(&socket); // declared elsewhere
void Sth::onReadyRead(){
while(socket.canReadLine()){
s = ts.readLine();
}
}
To copy to clipboard, switch view to plain text mode
If you insist on having it blocking:
bool stop = false;
while(!stop) {
while(!stop && socket.canReadLine()) {
s = ts.readLine();
if(s.trimmed()==".") stop = true;
}
if(!stop) socket.waitForReadyRead(5000);
}
bool stop = false;
while(!stop) {
while(!stop && socket.canReadLine()) {
s = ts.readLine();
if(s.trimmed()==".") stop = true;
}
if(!stop) socket.waitForReadyRead(5000);
}
To copy to clipboard, switch view to plain text mode
Your code is faulty bvecause you assume that after waitForReadyRead() there will be a complete line in the socket.
Bookmarks