Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QBuffer Class Reference

Inheritance diagram for QBuffer:

QIODevice QObject

List of all members.


Detailed Description

The QBuffer class provides a QIODevice interface for a QByteArray.

QBuffer allows you to access a QByteArray using the QIODevice interface. The QByteArray is treated just as a standard random-accessed file. Example:

snippets/buffer/buffer.cpp main_snippet QBuffer buffer /^/

By default, an internal QByteArray buffer is created for you when you create a QBuffer. You can access this buffer directly by calling buffer(). You can also use QBuffer with an existing QByteArray by calling setBuffer(), or by passing your array to QBuffer's constructor.

Call open() to open the buffer. Then call write() or putChar() to write to the buffer, and read(), readLine(), readAll(), or getChar() to read from it. size() returns the current size of the buffer, and you can seek to arbitrary positions in the buffer by calling seek(). When you are done with accessing the buffer, call close().

The following code snippet shows how to write data to a QByteArray using QDataStream and QBuffer:

write_datastream_snippet QByteArray /^/

Effectively, we convert the application's QPalette into a byte array. Here's how to read the data from the QByteArray:

read_datastream_snippet QPalette /^/

QTextStream and QDataStream also provide convenience constructors that take a QByteArray and that create a QBuffer behind the scenes.

QBuffer emits readyRead() when new data has arrived in the buffer. By connecting to this signal, you can use QBuffer to store temporary data before processing it. For example, you can pass the buffer to QFtp when downloading a file from an FTP server. Whenever a new payload of data has been downloaded, readyRead() is emitted, and you can process the data that just arrived. QBuffer also emits bytesWritten() every time new data has been written to the buffer.

See also:
QFile, QDataStream, QTextStream, QByteArray

Definition at line 57 of file qbuffer.h.


Public Types

enum  OpenModeFlag {
  NotOpen = 0x0000, ReadOnly = 0x0001, WriteOnly = 0x0002, ReadWrite = ReadOnly | WriteOnly,
  Append = 0x0004, Truncate = 0x0008, Text = 0x0010, Unbuffered = 0x0020
}

Public Slots

void deleteLater ()

Signals

void aboutToClose ()
void bytesWritten (qint64 bytes)
void destroyed (QObject *=0)
void readyRead ()

Public Member Functions

bool atEnd () const
bool blockSignals (bool b)
const QByteArraybuffer () const
QByteArraybuffer ()
virtual qint64 bytesAvailable () const
virtual qint64 bytesToWrite () const
bool canReadLine () const
const QObjectListchildren () const
void close ()
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
const QByteArraydata () const
bool disconnect (const QObject *receiver, const char *member=0)
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
void dumpObjectInfo ()
void dumpObjectTree ()
QList< QByteArraydynamicPropertyNames () const
QString errorString () const
virtual bool event (QEvent *)
virtual bool eventFilter (QObject *, QEvent *)
template<typename T>
findChild (const QString &name=QString()) const
template<typename T>
QList< T > findChildren (const QRegExp &re) const
template<typename T>
QList< T > findChildren (const QString &name=QString()) const
bool getChar (char *c)
bool inherits (const char *classname) const
void installEventFilter (QObject *)
bool isOpen () const
bool isReadable () const
virtual bool isSequential () const
bool isTextModeEnabled () const
bool isWidgetType () const
bool isWritable () const
void killTimer (int id)
void moveToThread (QThread *thread)
QString objectName () const
bool open (OpenMode openMode)
OpenMode openMode () const
QObjectparent () const
QByteArray peek (qint64 maxlen)
qint64 peek (char *data, qint64 maxlen)
qint64 pos () const
QVariant property (const char *name) const
bool putChar (char c)
 QBuffer (QByteArray *buf, QObject *parent=0)
 QBuffer (QObject *parent=0)
QByteArray read (qint64 maxlen)
qint64 read (char *data, qint64 maxlen)
QByteArray readAll ()
QByteArray readLine (qint64 maxlen=0)
qint64 readLine (char *data, qint64 maxlen)
void removeEventFilter (QObject *)
virtual bool reset ()
bool seek (qint64 off)
void setBuffer (QByteArray *a)
void setData (const char *data, int len)
void setData (const QByteArray &data)
void setObjectName (const QString &name)
void setParent (QObject *)
bool setProperty (const char *name, const QVariant &value)
void setTextModeEnabled (bool enabled)
void setUserData (uint id, QObjectUserData *data)
bool signalsBlocked () const
qint64 size () const
int startTimer (int interval)
QThreadthread () const
void ungetChar (char c)
QObjectUserData * userData (uint id) const
virtual bool waitForBytesWritten (int msecs)
virtual bool waitForReadyRead (int msecs)
qint64 write (const QByteArray &data)
qint64 write (const char *data, qint64 len)
 ~QBuffer ()

Static Public Member Functions

static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
static uint registerUserData ()

Protected Member Functions

virtual void childEvent (QChildEvent *)
virtual void connectNotify (const char *signal)
virtual void customEvent (QEvent *)
virtual void disconnectNotify (const char *signal)
qint64 readData (char *data, qint64 maxlen)
virtual qint64 readLineData (char *data, qint64 maxlen)
int receivers (const char *signal) const
QObjectsender () const
void setErrorString (const QString &errorString)
void setOpenMode (OpenMode openMode)
virtual void timerEvent (QTimerEvent *)
qint64 writeData (const char *data, qint64 len)

Protected Attributes

QObjectData * d_ptr

Static Protected Attributes

static const QMetaObject staticQtMetaObject

Properties

QString objectName
 the name of this object

Friends

class QApplication
class QApplicationPrivate
class QCoreApplication
class QCoreApplicationPrivate
struct QMetaObject
class QThreadData
class QWidget

Related Functions

(Note that these are not member functions.)

qFindChild (const QObject *obj, const QString &name=QString(), T dummy=0)
qFindChild (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QString &name=QString(), T dummy=0)
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
QList< T > qFindChildren (const QObject *obj, const QString &name)
T * qobject_cast (QObject *object)
 QObjectList
void * qt_find_obj_child (QObject *parent, const char *type, const QString &name)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index