QBuffer Class Reference


The QBuffer class is an I/O device that operates on a QByteArray More...

#include <qbuffer.h>

Inherits QIODevice.

List of all member functions.

Public Members


Detailed Description

The QBuffer class is an I/O device that operates on a QByteArray

QBuffer is an I/O device for reading and writing a memory buffer. A QFile may be used by itself (readBlock and writeBlock) or by more conveniently using 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.

The byte stream classes QDataStream and QTextStream have an constructor that creates an internal QBuffer that operates on a byte array.

Example:

    QString str;
    QTextStream ts( str, IO_WriteOnly );
    ts << "pi = " << 3.14;                      // str == "pi = 3.14"

See also: QFile, QDataStream and QTextStream.


Member Function Documentation

QBuffer::QBuffer ( QByteArray buf)

Constructs a buffer and sets the buffer contents to buf.

See also: setBuffer().

QBuffer::QBuffer ()

Constructs an empty buffer.

QBuffer::~QBuffer ()

Destroys the buffer.

bool QBuffer::at ( int pos) [virtual]

Sets the buffer index to pos. Returns TRUE if successful, otherwise FALSE.

See also: size().

Reimplemented from QIODevice.

int QBuffer::at () const [virtual]

Returns the buffer index.

See also: size().

Reimplemented from QIODevice.

void QBuffer::close () [virtual]

Closes an open buffer.

See also: open().

Reimplemented from QIODevice.

void QBuffer::flush () [virtual]

The flush function does nothing.

Reimplemented from QIODevice.

int QBuffer::getch () [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.

bool QBuffer::open ( int m) [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.

See also: close() and isOpen().

Reimplemented from QIODevice.

int QBuffer::putch ( int ch) [virtual]

Writes the character ch to the buffer.

Returns ch, or -1 if some error occurred.

See also: getch() and ungetch().

Reimplemented from QIODevice.

int QBuffer::readBlock ( char *p, uint len) [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.

int QBuffer::readLine ( char *p, uint maxlen) [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.

bool QBuffer::setBuffer ( QByteArray buf)

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

int QBuffer::ungetch ( int ch) [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.

int QBuffer::writeBlock ( const char *p, uint len) [virtual]

Writes len bytes from p to the buffer and returns the number of bytes actually written.

Returns -1 if a serious error occurred.

See also: readBlock().

Reimplemented from QIODevice.

uint QIODevice::size () const [virtual]

Virtual function that returns the size of the I/O device.

See also: at().

Reimplemented in QFile.


This file is part of the Qt toolkit, copyright © 1995-96 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:51, 1996/09/24 for Qt version 1.0 by the webmaster at Troll Tech