#include#include #include int main() { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); buffer.write("Hello, world!"); buffer.close(); // Close the buffer and flush data to QByteArray qDebug() << data; // Output the contents of the QByteArray }
#includeThis example creates a QByteArray object containing some data, and then creates a QBuffer object that is opened for reading. It reads all of the data from the buffer using the readAll() method, and then closes the buffer using the close() method. Finally, the contents of the data read from the buffer are output to the console using qDebug(). Package library: QtCore#include #include int main() { QByteArray data("Hello, world!"); QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); QByteArray contents = buffer.readAll(); buffer.close(); // Close the buffer qDebug() << contents; // Output the contents of the QByteArray }