Hmm... a socket is surely a buffered device and the default implementation of canReadLine() works fine with it.
Hmm... a socket is surely a buffered device and the default implementation of canReadLine() works fine with it.
The Storm (22nd March 2008)
Thanks, after some tests it seems that you are right.
One more question is readLine() called from the TcpSocket appends a terminating C character at the end of the string - '\0' ?
Yeah, I know that - I have used canReadLine() with QTcpSocket more than once
readLine returns a QByteArray, which I think is internally null terminated. But in general the last readable character in the string will be the newline character. You usually use it like so:One more question is readLine() called from the TcpSocket appends a terminating C character at the end of the string - '\0' ?
Qt Code:
while(sock->canReadLine()){ dat = dat.trimmed(); // removes leading and trailing whitespaces doSomethingWith(dat); }To copy to clipboard, switch view to plain text mode
Remember that QString uses 16b unicode so it is in general not null terminated (or to be precise a null character can exist inside the string).
Thanks alot, this trimmed() function is really usefull, it saves me some operation with the protocol that I'm parsing.Just one more question that is not related to the topic but I think that creating new one again will be to much for this days huh. :P
Is it good on client side to put the TcpSocket in other thread, because sometimes when the server side send things very fast I got error from server that the "socket is not ready" or something like that and if I put it in other thread will this problem dissapear and how I will be able to connect the signals from the QTcpSocket to the main GUI thread ?![]()
I don't know if the problem will disappear - I sincerely doubt that. Socket not being ready is probably some local issue independent of both the protocol or the speed of data flow, tcp should handle that quite nicely just by itself, without Qt interfering.
As for signals, you can safely use them across threads.
The Storm (26th March 2008)
Bookmarks