PDA

View Full Version : QBuffer::readLine()



vfernandez
23rd April 2010, 18:42
#include <QtCore>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QBuffer buf;
buf.open(QIODevice::ReadWrite);
buf.write("Hello!\n");
qDebug() << buf.data(); // prints Hello!\n
qDebug() << buf.canReadLine(); // returns false!
qDebug() << buf.readLine(); // returns an empty string!
}

I'm using QBuffer for a unit test and I've found this behaviour. I'm using 4.6.2. The Qt docs state you can use readLine() but in fact it returns an empty string. Is this correct or a Qt bug?

wysota
23rd April 2010, 20:52
This is correct. You didn't rewind the buffer. If you seek to the beginning of the buffer, you will be able to read from it.

vfernandez
23rd April 2010, 20:57
Oops! Dzękuje.