Quote Originally Posted by Pepe View Post
Is this correct?
Not quite. What if data arrives in two parts? You need a while loop that that will call waitForReadyRead() and readAll() until you read all of the data. You will have detect yourself if you read all of the data, to break that loop.

Quote Originally Posted by Pepe View Post
It seems that I only get the first line.
You get only one line, because you call readLine() once. You simply don't read the rest.

Quote Originally Posted by Pepe View Post
Is it necessary to use a QTextStream?
No.

Quote Originally Posted by Pepe View Post
Both QTextStream and QTcpSocket have a flush function, which one should I use?
You don't need the one from QTcpSocket. QTcpSocket::disconnectFromHost() should handle the unsent data. Also you should remove "socket->close()", because it's just an equivalent of disconnectFromHost().

PS. Why do you create both text stream and the socket on the heap, if you need them only in one function?