#include#include int main() { QByteArray data = "Hello, world!"; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); // open buffer for writing buffer.write("Hello"); // write data to buffer buffer.close(); // close buffer // output buffer data qDebug() << data; // prints: "Hello, world!" return 0; }
#includeBoth examples demonstrate the use of QBuffer to read from or write to a memory buffer instead of a file. The QBuffer class is part of the Qt Core module.#include int main() { QByteArray data = "Hello, world!"; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); // open buffer for reading qDebug() << buffer.readAll(); // read all data from buffer and output it buffer.close(); // close buffer return 0; }