QBuffer - I/O device that operates on a
#include <qbuffer.h>
Inherits QIODevice.
Public Members
QBuffer ()
QBuffer ( QByteArray )
~QBuffer ()
QByteArray buffer () const
bool setBuffer ( QByteArray )
DESCRIPTION
The QBuffer class is an I/O device that operates on a
QByteArray
QBuffer allows reading and writing a memory buffer. It is
normally used together with a QTextStream 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 QBuffer(QByteArray) creates a QBuffer with
an existing byte array. The byte array can also be set
with setBuffer(). Writing to the QBuffer will modify the
original byte array, since QByteArray 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().
The common way to use QBuffer is through QDataStream or
QTextStream which have constructors that take a QBuffer
parameter. For convenience, there are also QDataStream and
QTextStream constructors that take a QByteArray parameter.
These constructors create and open an internal QBuffer.
Note that QTextStream can also operate on a QString (a
Unicode string); a QBuffer cannot.
You can also use QBuffer directly through the standard
QIODevice functions readBlock(), writeBlock() readLine(),
at(), getch(), putch() and ungetch().
See also QFile, QDataStream, QTextStream, QByteArray and
Shared Classes
Examples: grapher/grapher.cpp
QBuffer::QBuffer ()
Constructs an empty buffer.
QBuffer::QBuffer ( QByteArray buf )
Constructs a buffer that operates on buf. If you open the
buffer in write mode (IO_WriteOnly or IO_ReadWrite) and
write something into the buffer, buf will be modified.
Example:
QCString str = "abc";
QBuffer b( str );
b.open( IO_WriteOnly );
b.at( 3 ); // position at \0
b.writeBlock( "def", 4 ); // write including \0
b.close();
// Now, str == "abcdef"
See also setBuffer().
QBuffer::~QBuffer ()
Destructs the buffer.
bool QBuffer::at ( int pos ) [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
int QBuffer::at () const [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
QByteArray QBuffer::buffer () const
Returns this buffer's byte array.
See also setBuffer().
void QBuffer::close () [virtual]
Reimplemented for internal reasons; the API is not
affected. Closes an open buffer.
See also open().
Examples: grapher/grapher.cpp
Reimplemented from QIODevice.
void QBuffer::flush () [virtual]
Reimplemented for internal reasons; the API is not
affected. The flush function does nothing for a QBuffer.
int QBuffer::getch () [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
bool QBuffer::open ( int m ) [virtual]
Reimplemented for internal reasons; the API is not
affected. Opens the buffer in the mode m. Returns TRUE if
successful, otherwise FALSE. The buffer must be opened
before use.
The mode parameter m must be a combination of the
following flags.
IO_ReadOnly opens a buffer in read-only mode.
IO_WriteOnly opens a buffer in write-only mode.
IO_ReadWrite opens a buffer in read/write mode.
IO_Append sets the buffer index to the end of the buffer.
IO_Truncate truncates the buffer.
See also close() and isOpen().
Examples: grapher/grapher.cpp
Reimplemented from QIODevice.
int QBuffer::putch ( int ch ) [virtual]
Reimplemented for internal reasons; the API is not
affected. Writes the character ch into the buffer,
overwriting the character at the current index, extending
the buffer if necessary.
Returns ch, or -1 if some error occurred.
See also getch() and ungetch().
Examples: grapher/grapher.cpp
Reimplemented from QIODevice.
int QBuffer::readBlock ( char * p, uint len ) [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
bool QBuffer::setBuffer ( QByteArray buf )
Replaces the buffer's contents with buf.
This may not be done when isOpen() is TRUE.
Note that if you open the buffer in write mode
(IO_WriteOnly or IO_ReadWrite) and write something into
the buffer, buf is also modified because QByteArray is an
explicitly shared class.
See also buffer(), open() and close().
uint QBuffer::size () const [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
int QBuffer::ungetch ( int ch ) [virtual]
Reimplemented for internal reasons; the API is not
affected.
Reimplemented from QIODevice.
int QBuffer::writeBlock ( const char * p, uint len ) [virtual]
Reimplemented for internal reasons; the API is not
affected.
Writes len bytes from p into the buffer at the current
index, overwriting any characters there and extending the
buffer if necessary. Returns the number of bytes actually
written.
Returns -1 if a serious error occurred.
See also readBlock().
Reimplemented from QIODevice.
SEE ALSO
http://doc.trolltech.com/qbuffer.html
http://www.trolltech.com/faq/tech.html
COPYRIGHT
Copyright 1992-2001 Trolltech AS,
http://www.trolltech.com. See the license file included
in the distribution for a complete license statement.
Generated automatically from the source code.
BUGS
If you find a bug in Qt, please report it as described in
http://doc.trolltech.com/bughowto.html. Good bug reports
make our job much simpler. Thank you.
In case of content or formattting problems with this
manual page, please report them to qt-bugs@trolltech.com.
Please include the name of the manual page (qbuffer.3qt)
and the Qt version (2.3.1).
Man(1) output converted with
man2html