QBuffer is used to read and write to a memory buffer. It is normally used with a TQTextStream or a QDataStream. QBuffer has an associated QByteArray which holds the buffer data. The size() of the buffer is automatically adjusted as data is written.
The constructor \fCQBuffer(QByteArray)\fR creates a QBuffer using an existing byte array. The byte array can also be set with setBuffer(). Writing to the QBuffer will modify the original byte array because QByteArray is explicitly shared.
.PP
Use open() to open the buffer before use and to set the mode (read-only, write-only, etc.). close() closes the buffer. The buffer must be closed before reopening or calling setBuffer().
A common way to use QBuffer is through QDataStream or TQTextStream, which have constructors that take a QBuffer parameter. For convenience, there are also QDataStream and TQTextStream constructors that take a QByteArray parameter. These constructors create and open an internal QBuffer.
You can also use QBuffer directly through the standard TQIODevice functions readBlock(), writeBlock() readLine(), at(), getch(), putch() and ungetch().
If you open the buffer in write mode (<a href="ntqfile.html#open">IO_WriteOnly</a> or IO_ReadWrite) and write something into the buffer, \fIbuf\fR will be modified.
Note that if you open the buffer in write mode (<a href="ntqfile.html#open">IO_WriteOnly</a> or IO_ReadWrite) and write something into the buffer, \fIbuf\fR is also modified because QByteArray is an explicitly shared class.
Writes \fIlen\fR bytes from \fIp\fR into the buffer at the current index position, overwriting any characters there and extending the buffer if necessary. Returns the number of bytes actually written.