CopperSpice API
1.9.2
|
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 pos) override |
void | setBuffer (QByteArray *buffer) |
void | setData (const char *data, int size) |
void | setData (const QByteArray &buffer) |
qint64 | size () const override |
Public Methods inherited from QIODevice | |
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) |
Public Methods inherited from QObject | |
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 &childName=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 size) override |
qint64 | writeData (const char *data, qint64 size) override |
Protected Methods inherited from QIODevice | |
virtual qint64 | readLineData (char *data, qint64 maxSize) |
void | setErrorString (const QString &errorString) |
void | setOpenMode (OpenMode openMode) |
Protected Methods inherited from QObject | |
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 | |
Public Typedefs inherited from QIODevice | |
using | OpenMode = QFlags< OpenModeFlag > |
Public Types inherited from QIODevice | |
enum | OpenModeFlag |
Public Signals inherited from QIODevice | |
void | aboutToClose () |
void | bytesWritten (qint64 bytes) |
void | readChannelFinished () |
void | readyRead () |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots inherited from QObject | |
void | deleteLater () |
Static Public Methods inherited from QObject | |
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 >()) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QBuffer class provides a QIODevice interface for a QByteArray. This class 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 the QBuffer 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 constructors which take a QByteArray and create a QBuffer.
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 |
Reimplemented from QIODevice::atEnd()
QByteArray & QBuffer::buffer | ( | ) |
Returns a reference to the QBuffer's internal buffer. You can use it to modify the QByteArray.
const QByteArray & QBuffer::buffer | ( | ) | const |
Equivalent to calling data().
|
overridevirtual |
Reimplemented from QIODevice::canReadLine()
|
overridevirtual |
Reimplemented from QIODevice::close()
|
overrideprotectedvirtual |
This method is called when a connection has been made to signalMethod in this object.
Reimplemented from QObject::connectNotify()
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::disconnectNotify()
|
overridevirtual |
Reimplemented from QIODevice::open()
|
overridevirtual |
Reimplemented from QIODevice::pos()
Implements QIODevice::readData()
|
overridevirtual |
Reimplemented from QIODevice::seek()
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 |
Reimplemented from QIODevice::size()
Implements QIODevice::writeData()