Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QBuffer class provides a QIODevice interface for a QByteArray. More...
#include <QBuffer>
Inherits QIODevice.
Note: All the functions in this class are reentrant.
The QBuffer class provides a QIODevice interface for a QByteArray.
QBuffer is a wrapper for QByteArray which allows you to access an array using the QIODevice interface. The QByteArray is treated as a FIFO queue (First In, First Out), so the first data you write to the buffer is the first data you will read. Example:
QBuffer buffer; if (buffer.open(QBuffer::ReadWrite)) { buffer.write("Qt rocks!"); char c; buffer.getChar(&c); // 'Q' buffer.getChar(&c); // 't' buffer.getChar(&c); // ' ' buffer.getChar(&c); // 'r' }
By default, an internal QByteArray buffer is created for you when you construct 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().
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, your slot connected to readyRead() will be called. QBuffer also emits bytesWritten() every time new data has been written to the buffer.
QBuffer can be used with QTextStream and QDataStream's stream operators (operator<<() and operator>>()).
See also QFile, QDataStream, QTextStream, QByteArray, and Shared Classes.
Constructs an empty buffer.
Constructs a buffer that operates on QByteArray a.
If you open the buffer in write mode (QIODevice::WriteOnly or QIODevice::ReadWrite) and write something into the buffer, the byte array, a will be modified.
Example:
QCString str = "abc"; QBuffer b(str); b.open(QIODevice::WriteOnly); b.at(3); // position at the 4th character (the terminating \0) b.writeBlock("def", 4); // write "def" including the terminating \0 b.close(); // Now, str == "abcdef" with a terminating \0
See also setBuffer().
Constructs an empty buffer with the parent parent.
Constructs a buffer that operates on QByteArray a, with the parent parent.
Destroys the buffer.
Returns this buffer's byte array.
See also setBuffer().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns this buffer's byte array.
See also setBuffer().
Returns this buffer's byte array.
See also setData().
Replaces the buffer's contents with a.
Does nothing if isOpen() is true.
Note that if you open the buffer in write mode (QIODevice::WriteOnly or QIODevice::ReadWrite) and write something into the buffer, and a is not 0, a is modified because QByteArray is an explicitly shared class.
If a is 0, the buffer creates its own (initially empty) internal QByteArray to work on.
See also buffer(), open(), and close().
Sets the byte array for the buffer to be data.
Does nothing if isOpen() is true. Since data is const the buffer can only be used to read from it.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the data to be the first len bytes of the data string.
Copyright © 2004 Trolltech | Trademarks | Qt 4.0.0-b1 |