How to Create and Use Buffers in Qt

Posted on Posted in Qt Tutorials, Tutorials

Qt Framework includes a class called QBuffer that can be used to access a QByteArray (internal QByteArray to be precise) as if it is a file. So you can use Stream readers and writers to access data in it similar to a QFile.

Here is a brief example:

QBuffer b;
b.open(QBuffer::ReadWrite);
b.write(“http://amin-ahmadi.com”);
qDebug() << b.size(); // 22
b.seek(0);
qDebug() << b.read(11); // “http://amin”
b.seek(20);
qDebug() << b.read(1); // “o”
b.close();





Leave a Reply

Your email address will not be published. Required fields are marked *