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 TQByteArray which holds the buffer data. The size() of the buffer is automatically adjusted as data is written.
The constructor \fCQBuffer(TQByteArray)\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 TQByteArray is explicitly shared.
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 TQByteArray 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 TQByteArray 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.