43 #include "private/qiodevice_p.h" 164 d->buf = &
d->defaultBuf;
171 d->buf = buf ?
buf : &
d->defaultBuf;
173 d->defaultBuf.clear();
187 d->buf = &
d->defaultBuf;
212 d->buf = byteArray ? byteArray : &
d->defaultBuf;
213 d->defaultBuf.clear();
252 qWarning(
"QBuffer::setBuffer: Buffer is open");
258 d->buf = &
d->defaultBuf;
260 d->defaultBuf.clear();
319 qWarning(
"QBuffer::setData: Buffer is open");
345 qWarning(
"QBuffer::open: Buffer access not specified");
388 if (
seek(
d->buf->size())) {
389 const qint64 gapSize = pos -
d->buf->size();
391 qWarning(
"QBuffer::seek: Unable to fill gap");
397 }
else if (pos >
d->buf->size() || pos < 0) {
398 qWarning(
"QBuffer::seek: Invalid pos: %d",
int(pos));
401 d->ioIndex = int(pos);
431 if ((len =
qMin(len,
qint64(
d->buf->size()) -
d->ioIndex)) <= 0)
433 memcpy(data,
d->buf->constData() +
d->ioIndex, len);
434 d->ioIndex += int(len);
444 int extraBytes =
d->ioIndex + len -
d->buf->size();
445 if (extraBytes > 0) {
446 int newSize =
d->buf->size() + extraBytes;
447 d->buf->resize(newSize);
448 if (
d->buf->size() != newSize) {
449 qWarning(
"QBuffer::writeData: Memory allocation error");
454 memcpy(
d->buf->data() +
d->ioIndex, (
uchar *)data,
int(len));
455 d->ioIndex += int(len);
457 #ifndef QT_NO_QOBJECT 458 d->writtenSinceLastEmit += len;
460 d->signalsEmitted =
true;
467 #ifndef QT_NO_QOBJECT 474 if (strcmp(signal + 1,
"readyRead()") == 0 || strcmp(signal + 1,
"bytesWritten(qint64)") == 0)
475 d_func()->signalConnectionCount++;
484 if (!signal || strcmp(signal + 1,
"readyRead()") == 0 || strcmp(signal + 1,
"bytesWritten(qint64)") == 0)
485 d_func()->signalConnectionCount--;
491 #ifndef QT_NO_QOBJECT 492 # include "moc_qbuffer.cpp"
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
const QByteArray & data() const
Returns the data contained in the buffer.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
bool open(OpenMode openMode)
Reimplemented Function
The QByteArray class provides an array of bytes.
void close()
Reimplemented Function
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
qint64 pos() const
Reimplemented Function
qint64 size() const
Reimplemented Function
The QBuffer class provides a QIODevice interface for a QByteArray.
The QObject class is the base class of all Qt objects.
void setBuffer(QByteArray *a)
Makes QBuffer uses the QByteArray pointed to by byteArray as its internal buffer. ...
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
bool canReadLine() const
Reimplemented Function
bool seek(qint64 off)
Reimplemented Function
virtual qint64 peek(char *data, qint64 maxSize)
QBuffer(QObject *parent=0)
Constructs an empty buffer with the given parent.
bool atEnd() const
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QByteArray & buffer()
Returns a reference to the QBuffer's internal buffer.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
~QBuffer()
Destroys the buffer.
qint64 readData(char *data, qint64 maxlen)
Reimplemented Function
void connectNotify(const char *)
Reimplemented Function
const char * constData() const
Returns a pointer to the data stored in the byte array.
#define Q_DECLARE_PUBLIC(Class)
int signalConnectionCount
QObject * parent() const
Returns a pointer to the parent object.
qint64 writtenSinceLastEmit
int size() const
Returns the number of bytes in this byte array.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
void disconnectNotify(const char *)
Reimplemented Function
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
bool signalsBlocked() const
Returns true if signals are blocked; otherwise returns false.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
The QIODevice class is the base interface class of all I/O devices in Qt.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
qint64 writeData(const char *data, qint64 len)
Reimplemented Function