blue.death
8th August 2006, 19:47
Hi guys,
I am going nuts with a strange (for me!) behaviour in QTextStream's atEnd() method.
As far as YOU know, shoundn't the method return true if there is no more data that can be read?
Now what if I call it, it returns true, then I call readLine() and it returns data!
I discovered this quite strange behaviour when trying to read data from a socket in a SMTP client I am writing.
I have something like this:
QTextStream s(mySocketPointer);
bool isAtEnd = s.atEnd(); // <-- returns TRUE!
QString line = s.readLine(); // <-- returns a non empty string!!
To say the truth I use a QTextStream subclass that relies on QTextStream::atEnd() to detect if there is more data to be read in the readLine() method.
The class works well with a standard QTcpSocket (atEnd() returns false!) but I have the problem when using a QtSslSocket (from Trolltech's Qt solutions).
Any clues?
I cannot post any code as the QtSslSocket is only available to users with a commercial license. Sorry :(
PS: It is not a a matter of bad timings between the call to atEnd() and readLine() as I read the data in a slot connected to the socket's readyRead() signal, so I expect to be data in the buffer and that call to atEnd() should return true!!!
I am going nuts with a strange (for me!) behaviour in QTextStream's atEnd() method.
As far as YOU know, shoundn't the method return true if there is no more data that can be read?
Now what if I call it, it returns true, then I call readLine() and it returns data!
I discovered this quite strange behaviour when trying to read data from a socket in a SMTP client I am writing.
I have something like this:
QTextStream s(mySocketPointer);
bool isAtEnd = s.atEnd(); // <-- returns TRUE!
QString line = s.readLine(); // <-- returns a non empty string!!
To say the truth I use a QTextStream subclass that relies on QTextStream::atEnd() to detect if there is more data to be read in the readLine() method.
The class works well with a standard QTcpSocket (atEnd() returns false!) but I have the problem when using a QtSslSocket (from Trolltech's Qt solutions).
Any clues?
I cannot post any code as the QtSslSocket is only available to users with a commercial license. Sorry :(
PS: It is not a a matter of bad timings between the call to atEnd() and readLine() as I read the data in a slot connected to the socket's readyRead() signal, so I expect to be data in the buffer and that call to atEnd() should return true!!!