The QBuffer class is an I/O device that operates on a QByteArray More...
#include <qbuffer.h>
Inherits QIODevice.
QBuffer is an I/O device for reading and writing a memory buffer. A QBuffer may be used directly (readBlock() and writeBlock()) or more conveniently via QDataStream or QTextStream. Most of its behavior is inherited from QIODevice.
A QBuffer has an associated QByteArray which holds the buffer data. Writing data at the end (i.e. size()) of the buffer expands the byte array.
For convenience, the byte stream classes QDataStream and QTextStream can operate on a QByteArray (or a QString) via an internal QBuffer:
QString str; QTextStream ts( str, IO_WriteOnly ); ts << "pi = " << 3.14; // str == "pi = 3.14"
See also: QFile, QDataStream and QTextStream.
Examples: grapher/grapher.cpp
Constructs an empty buffer.
Constructs a buffer and sets the buffer contents to buf.
See also: setBuffer().
Destroys the buffer.
[virtual]
Sets the buffer index to pos. Returns TRUE if successful, otherwise FALSE.
See also: size().
Reimplemented from QIODevice.
[virtual]
Returns the buffer index.
See also: size().
Reimplemented from QIODevice.
Returns the buffer most recently set by setBuffer(), or at construction.
[virtual]
Closes an open buffer.
See also: open().
Examples: grapher/grapher.cpp
Reimplemented from QIODevice.
[virtual]
The flush function does nothing.
Reimplemented from QIODevice.
[virtual]
Reads a single byte/character from the buffer.
Returns the byte/character read, or -1 if the end of the buffer has been reached.
See also: putch() and ungetch().
Reimplemented from QIODevice.
[virtual]
Opens the file specified by the file name currently set, using the mode m. Returns TRUE if successful, otherwise FALSE.
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.
[virtual]
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.
[virtual]
Reads at most len bytes from the buffer into p and returns the number of bytes actually read.
Returns -1 if a serious error occurred.
See also: writeBlock().
Reimplemented from QIODevice.
[virtual]
Reads a line of text.
Reads bytes from the buffer until end-of-line is reached, or up to maxlen bytes.
See also: readBlock().
Reimplemented from QIODevice.
Replaces the buffer's contents with buf.
This may not be done while the buffer is open.
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.
Example:
QString 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: open and Shared Classes
[virtual]
Returns the number of bytes in the buffer.
See also: at().
Reimplemented from QIODevice.
[virtual]
Puts the character ch back into the buffer and decrements the index if it is not zero.
This function is normally called to "undo" a getch() operation.
Returns ch, or -1 if some error occurred.
See also: getch() and putch().
Reimplemented from QIODevice.
[virtual]
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.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.
It was generated from the following files:
Copyright © 1998 Troll Tech | Trademarks | Qt version 1.42
|