Qt 4.8
|
The QBuffer class provides a QIODevice interface for a QByteArray. More...
#include <qbuffer.h>
Public Functions | |
bool | atEnd () const |
Reimplemented Function More... | |
QByteArray & | buffer () |
Returns a reference to the QBuffer's internal buffer. More... | |
const QByteArray & | buffer () const |
This is the same as data(). More... | |
bool | canReadLine () const |
Reimplemented Function More... | |
void | close () |
Reimplemented Function More... | |
const QByteArray & | data () const |
Returns the data contained in the buffer. More... | |
bool | open (OpenMode openMode) |
Reimplemented Function More... | |
qint64 | pos () const |
Reimplemented Function More... | |
QBuffer (QObject *parent=0) | |
Constructs an empty buffer with the given parent. More... | |
QBuffer (QByteArray *buf, QObject *parent=0) | |
Constructs a QBuffer that uses the QByteArray pointed to by byteArray as its internal buffer, and with the given parent. More... | |
bool | seek (qint64 off) |
Reimplemented Function More... | |
void | setBuffer (QByteArray *a) |
Makes QBuffer uses the QByteArray pointed to by byteArray as its internal buffer. More... | |
void | setData (const QByteArray &data) |
Sets the contents of the internal buffer to be data. More... | |
void | setData (const char *data, int len) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the contents of the internal buffer to be the first size bytes of data. More... | |
qint64 | size () const |
Reimplemented Function More... | |
~QBuffer () | |
Destroys the buffer. More... | |
Public Functions inherited from QIODevice | |
virtual qint64 | bytesAvailable () const |
Returns the number of bytes that are available for reading. More... | |
virtual qint64 | bytesToWrite () const |
For buffered devices, this function returns the number of bytes waiting to be written. More... | |
QString | errorString () const |
Returns a human-readable description of the last device error that occurred. More... | |
bool | getChar (char *c) |
Reads one character from the device and stores it in c. More... | |
bool | isOpen () const |
Returns true if the device is open; otherwise returns false. More... | |
bool | isReadable () const |
Returns true if data can be read from the device; otherwise returns false. More... | |
virtual bool | isSequential () const |
Returns true if this device is sequential; otherwise returns false. More... | |
bool | isTextModeEnabled () const |
Returns true if the Text flag is enabled; otherwise returns false. More... | |
bool | isWritable () const |
Returns true if data can be written to the device; otherwise returns false. More... | |
OpenMode | openMode () const |
Returns the mode in which the device has been opened; i.e. More... | |
qint64 | peek (char *data, qint64 maxlen) |
Reads at most maxSize bytes from the device into data, without side effects (i. More... | |
QByteArray | peek (qint64 maxlen) |
Peeks at most maxSize bytes from the device, returning the data peeked as a QByteArray. More... | |
bool | putChar (char c) |
Writes the character c to the device. More... | |
QIODevice () | |
Constructs a QIODevice object. More... | |
QIODevice (QObject *parent) | |
Constructs a QIODevice object with the given parent. More... | |
qint64 | read (char *data, qint64 maxlen) |
Reads at most maxSize bytes from the device into data, and returns the number of bytes read. More... | |
QByteArray | read (qint64 maxlen) |
Reads at most maxSize bytes from the device, and returns the data read as a QByteArray. More... | |
QByteArray | readAll () |
Reads all available data from the device, and returns it as a QByteArray. More... | |
qint64 | readLine (char *data, qint64 maxlen) |
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read. More... | |
QByteArray | readLine (qint64 maxlen=0) |
Reads a line from the device, but no more than maxSize characters, and returns the result as a QByteArray. More... | |
virtual bool | reset () |
Seeks to the start of input for random-access devices. More... | |
void | setTextModeEnabled (bool enabled) |
If enabled is true, this function sets the Text flag on the device; otherwise the Text flag is removed. More... | |
void | ungetChar (char c) |
Puts the character c back into the device, and decrements the current position unless the position is 0. More... | |
virtual bool | waitForBytesWritten (int msecs) |
For buffered devices, this function waits until a payload of buffered written data has been written to the device and the bytesWritten() signal has been emitted, or until msecs milliseconds have passed. More... | |
virtual bool | waitForReadyRead (int msecs) |
Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. More... | |
qint64 | write (const char *data, qint64 len) |
Writes at most maxSize bytes of data from data to the device. More... | |
qint64 | write (const char *data) |
Writes data from a zero-terminated string of 8-bit characters to the device. More... | |
qint64 | write (const QByteArray &data) |
Writes the content of byteArray to the device. More... | |
virtual | ~QIODevice () |
The destructor is virtual, and QIODevice is an abstract base class. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Protected Functions | |
void | connectNotify (const char *) |
Reimplemented Function More... | |
void | disconnectNotify (const char *) |
Reimplemented Function More... | |
qint64 | readData (char *data, qint64 maxlen) |
Reimplemented Function More... | |
qint64 | writeData (const char *data, qint64 len) |
Reimplemented Function More... | |
Protected Functions inherited from QIODevice | |
QIODevice (QIODevicePrivate &dd, QObject *parent=0) | |
virtual qint64 | readLineData (char *data, qint64 maxlen) |
Reads up to maxSize characters into data and returns the number of characters read. More... | |
void | setErrorString (const QString &errorString) |
Sets the human readable description of the last device error that occurred to str. More... | |
void | setOpenMode (OpenMode openMode) |
Sets the OpenMode of the device to openMode. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Additional Inherited Members | |
Public Types inherited from QIODevice | |
enum | OpenModeFlag { NotOpen = 0x0000, ReadOnly = 0x0001, WriteOnly = 0x0002, ReadWrite = ReadOnly | WriteOnly, Append = 0x0004, Truncate = 0x0008, Text = 0x0010, Unbuffered = 0x0020 } |
This enum is used with open() to describe the mode in which a device is opened. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals inherited from QIODevice | |
void | aboutToClose () |
This signal is emitted when the device is about to close. More... | |
void | bytesWritten (qint64 bytes) |
This signal is emitted every time a payload of data has been written to the device. More... | |
void | readChannelFinished () |
This signal is emitted when the input (reading) stream is closed in this device. More... | |
void | readyRead () |
This signal is emitted once every time new data is available for reading from the device. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
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:
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:
Effectively, we convert the application's QPalette into a byte array. Here's how to read the data from the QByteArray:
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.
|
explicit |
Constructs an empty buffer with the given parent.
You can call setData() to fill the buffer with data, or you can open it in write mode and use write().
Definition at line 183 of file qbuffer.cpp.
Referenced by QBufferPrivate::peek().
QBuffer::QBuffer | ( | QByteArray * | byteArray, |
QObject * | parent = 0 |
||
) |
Constructs a QBuffer that uses the QByteArray pointed to by byteArray as its internal buffer, and with the given parent.
The caller is responsible for ensuring that byteArray remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, byteArray will be modified.
Example:
Definition at line 208 of file qbuffer.cpp.
QBuffer::~QBuffer | ( | ) |
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 408 of file qbuffer.cpp.
Referenced by QAxServerBase::Load().
QByteArray & QBuffer::buffer | ( | ) |
Returns a reference to the QBuffer's internal buffer.
You can use it to modify the QByteArray behind the QBuffer's back.
Definition at line 271 of file qbuffer.cpp.
Referenced by QPicturePrivate::checkFormat(), QTestLiteStaticInfoPrivate::initializeSupportedAtoms(), QXlibMime::mimeConvertToFormat(), QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(), qt_get_net_supported(), qt_get_net_virtual_roots(), QAxServerBase::Save(), and QX11Data::xdndMimeConvertToFormat().
const QByteArray & QBuffer::buffer | ( | ) | const |
This is the same as data().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 286 of file qbuffer.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 416 of file qbuffer.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 359 of file qbuffer.cpp.
Referenced by QPicturePrivate::checkFormat(), QPacket::clear(), QSvgPaintEngine::drawImage(), QXmlQuery::evaluateTo(), QAxServerBase::Load(), QFontEngineQPF::QFontEngineQPF(), QCacheItem::reset(), QAxServerBase::Save(), and QTextEditMimeData::setup().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QObject.
Definition at line 472 of file qbuffer.cpp.
const QByteArray & QBuffer::data | ( | ) | const |
Returns the data contained in the buffer.
This is the same as buffer().
Definition at line 301 of file qbuffer.cpp.
Referenced by QXmlQuery::evaluateTo(), QSvgIOHandlerPrivate::load(), QFontEngineQPF::QFontEngineQPF(), QPicturePrivate::QPicturePrivate(), qt_fill_input_buffer(), QWSServer::sendIMEvent(), setData(), QTextEditMimeData::setup(), and QTextOdfWriter::writeInlineCharacter().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QObject.
Definition at line 482 of file qbuffer.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 338 of file qbuffer.cpp.
Referenced by RequestAnalyzer::analyze(), QPicturePrivate::checkFormat(), QPacket::clear(), QNetworkDiskCache::data(), QDeclarativeXmlQueryEngine::doQueryJob(), QDeclarativeXmlQueryEngine::doSubQueryJob(), QSvgPaintEngine::drawImage(), QMimeDataWrapper::encodedData(), QXmlQuery::evaluateTo(), QRasterPixmapData::fromData(), QVGPixmapData::fromData(), QPixmapData::fromData(), QGLPixmapData::fromData(), QImage::fromData(), QTestLiteStaticInfoPrivate::initializeSupportedAtoms(), QXmlSchemaPrivate::load(), QAxServerBase::Load(), QXlibMime::mimeConvertToFormat(), QDeclarativePixmapReader::networkRequestDone(), QNetworkAccessManager::post(), QNetworkDiskCache::prepare(), QNetworkAccessManager::put(), QDataStream::QDataStream(), QFontEngineQPF::QFontEngineQPF(), QPacket::QPacket(), QPicturePrivate::QPicturePrivate(), qt_get_net_supported(), qt_get_net_virtual_roots(), QTextStream::QTextStream(), QAxServerBase::Save(), QWSServer::sendIMEvent(), QXmlQuery::setFocus(), QMovie::supportedFormats(), QXmlSchemaValidator::validate(), ICOReader::write(), and QX11Data::xdndMimeConvertToFormat().
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 367 of file qbuffer.cpp.
Referenced by canReadLine(), QSvgIOHandlerPrivate::load(), QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(), QPicturePrivate::QPicturePrivate(), and qt_fill_input_buffer().
Reimplemented Function
Implements QIODevice.
Definition at line 428 of file qbuffer.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 384 of file qbuffer.cpp.
Referenced by QDeclarativeXmlQueryEngine::doSubQueryJob(), QSvgIOHandlerPrivate::load(), and QPicturePrivate::QPicturePrivate().
void QBuffer::setBuffer | ( | QByteArray * | byteArray | ) |
Makes QBuffer uses the QByteArray pointed to by byteArray as its internal buffer.
The caller is responsible for ensuring that byteArray remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.
Does nothing if isOpen() is true.
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, byteArray will be modified.
Example:
If byteArray is 0, the buffer creates its own internal QByteArray to work on. This byte array is initially empty.
Definition at line 248 of file qbuffer.cpp.
Referenced by QPacket::clear().
void QBuffer::setData | ( | const QByteArray & | data | ) |
Sets the contents of the internal buffer to be data.
This is the same as assigning data to buffer().
Does nothing if isOpen() is true.
Definition at line 315 of file qbuffer.cpp.
Referenced by QNetworkDiskCache::data(), QImage::fromData(), QNetworkAccessManager::post(), QNetworkAccessManager::put(), QDataStream::QDataStream(), QPicturePrivate::QPicturePrivate(), QTextStream::QTextStream(), QDomDocument::setContent(), and QXmlQuery::setFocus().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the contents of the internal buffer to be the first size bytes of data.
Definition at line 105 of file qbuffer.h.
|
virtual |
Reimplemented Function
Reimplemented from QIODevice.
Definition at line 375 of file qbuffer.cpp.
Referenced by QPicturePrivate::checkFormat(), QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(), QPicturePrivate::QPicturePrivate(), QWSServer::sendIMEvent(), and QCacheItem::size().
Reimplemented Function
Implements QIODevice.
Definition at line 441 of file qbuffer.cpp.