![]() |
CopperSpice API
1.7.4
|
The QBuffer class provides a QIODevice interface for a QByteArray. More...
Public Methods | |
QBuffer (QByteArray *buffer, QObject *parent=nullptr) | |
QBuffer (QObject *parent=nullptr) | |
~QBuffer () | |
bool | atEnd () const override |
QByteArray & | buffer () |
const QByteArray & | buffer () const |
bool | canReadLine () const override |
void | close () override |
const QByteArray & | data () const |
bool | open (OpenMode openMode) override |
qint64 | pos () const override |
bool | seek (qint64 off) override |
void | setBuffer (QByteArray *buffer) |
void | setData (const char *data, int size) |
void | setData (const QByteArray &buffer) |
qint64 | size () const override |
![]() | |
QIODevice () | |
QIODevice (QObject *parent) | |
virtual | ~QIODevice () |
virtual qint64 | bytesAvailable () const |
virtual qint64 | bytesToWrite () const |
QString | errorString () const |
bool | getChar (char *c) |
bool | isOpen () const |
bool | isReadable () const |
virtual bool | isSequential () const |
bool | isTextModeEnabled () const |
bool | isWritable () const |
OpenMode | openMode () const |
qint64 | peek (char *data, qint64 maxSize) |
QByteArray | peek (qint64 maxSize) |
bool | putChar (char c) |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize=0) |
virtual bool | reset () |
void | setTextModeEnabled (bool enabled) |
void | ungetChar (char c) |
virtual bool | waitForBytesWritten (int msecs) |
virtual bool | waitForReadyRead (int msecs) |
qint64 | write (const char *data) |
qint64 | write (const char *data, qint64 maxSize) |
qint64 | write (const QByteArray &data) |
![]() | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Protected Methods | |
void | connectNotify (const QMetaMethod &signalMethod) const override |
void | disconnectNotify (const QMetaMethod &signalMethod) const override |
qint64 | readData (char *data, qint64 maxSize) override |
qint64 | writeData (const char *data, qint64 size) override |
![]() | |
virtual qint64 | readLineData (char *data, qint64 maxSize) |
void | setErrorString (const QString &errorString) |
void | setOpenMode (OpenMode openMode) |
![]() | |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Additional Inherited Members | |
![]() | |
using | OpenMode = QFlags< OpenModeFlag > |
![]() | |
enum | OpenModeFlag |
![]() | |
void | aboutToClose () |
void | bytesWritten (qint64 bytes) |
void | readChannelFinished () |
void | readyRead () |
![]() | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
![]() | |
void | deleteLater () |
![]() | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
![]() | |
objectName | |
![]() | |
T | qobject_cast (QObject *object) |
QObjectList | |
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.
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 shows how to write data to a QByteArray using QDataStream and QBuffer.
Effectively, we convert the application's QPalette into a byte array. This is an example of 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 |
QBuffer::QBuffer | ( | QByteArray * | buffer, |
QObject * | parent = nullptr |
||
) |
Constructs a QBuffer that uses the QByteArray pointed to by buffer as its internal buffer, and with the given parent. The caller is responsible for ensuring that buffer remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer does not take ownership of the QByteArray.
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, buffer will be modified.
QBuffer::~QBuffer | ( | ) |
Destroys the buffer.
|
overridevirtual |
Returns true if the current read and write position is at the end of the device otherwise returns false. For some devices atEnd() can return true even though there is more data to read. This special case only applies to devices which generate data in direct response to calling read().
Reimplemented from QIODevice.
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.
const QByteArray & QBuffer::buffer | ( | ) | const |
Equivalent to calling data().
|
overridevirtual |
Returns true if a complete line of data can be read from the device, otherwise returns false. Unbuffered devices, which have no way of determining what can be read, always return false. This method is often called in conjunction with the readyRead() signal.
Subclasses that reimplement this method must call the base implementation in order to include the contents of the QIODevice's buffer.
Reimplemented from QIODevice.
|
overridevirtual |
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. The error string is also reset.
Reimplemented from QIODevice.
|
overrideprotectedvirtual |
This method is called when a connection has been made to signalMethod in this object.
Reimplemented from QObject.
const QByteArray & QBuffer::data | ( | ) | const |
Returns the data contained in the buffer. Equivalent to calling buffer().
|
overrideprotectedvirtual |
This method is called when a slot is disconnected from signalMethod in this object.
Reimplemented from QObject.
|
overridevirtual |
Opens the device and sets its OpenMode to mode. Returns true if successful, otherwise returns false. This method should be called from any existing reimplementation of open() or other functions that open the device.
Reimplemented from QIODevice.
|
overridevirtual |
For random-access devices, this method returns the position that data is written to or read from. For sequential devices or closed devices, where there is no concept of a "current position", 0 is returned.
The current read/write position of the device is maintained internally by QIODevice, so reimplementing this method is not necessary. When subclassing QIODevice, use QIODevice::seek() to notify QIODevice about changes in the device position.
Reimplemented from QIODevice.
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred. If there are no bytes to be read and there can never be more bytes available (examples include socket closed, pipe closed, sub-process finished), returns -1.
This method is called by QIODevice. Reimplement this method when creating a subclass of QIODevice.
When reimplementing it is important this method reads all the required data before returning. This is required in order for QDataStream to be able to operate on the class. QDataStream assumes all the requested information was read and therefore does not retry reading if there was a problem.
Implements QIODevice.
|
overridevirtual |
For random-access devices, this method sets the current position to pos, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.
When subclassing QIODevice, you must call QIODevice::seek() at the start of your function to ensure integrity with QIODevice's built-in buffer. The base implementation always returns true.
Reimplemented from QIODevice.
void QBuffer::setBuffer | ( | QByteArray * | buffer | ) |
Makes QBuffer uses the QByteArray pointed to by buffer 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 does not 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 buffer will be modified.
If buffer is a nullptr the QBuffer creates its own internal QByteArray. This byte array is initially empty.
|
inline |
Sets the contents of the internal buffer to be the first size bytes of data.
void QBuffer::setData | ( | const QByteArray & | buffer | ) |
Sets the contents of the internal buffer to be buffer. This is the same as assigning data to buffer(). This method does nothing if isOpen() is true.
|
overridevirtual |
For open random-access devices, this method returns the size of the device. For open sequential devices, bytesAvailable() is returned.If the device is closed, the size returned will not reflect the actual size of the device.
Reimplemented from QIODevice.
Writes up to maxSize bytes from data to the device. Returns the number of bytes written, or -1 if an error occurred.
This method is called by QIODevice. Reimplement when creating a subclass of QIODevice. When reimplementing it is important that this method writes all the data available before returning. This is required in order for QDataStream to be able to operate on the class. QDataStream assumes all the information was written and therefore does not retry writing if there was a problem.
Implements QIODevice.