Qt 4.8
Public Functions | Protected Functions | Protected Variables | List of all members
QByteDeviceWrappingIoDevice Class Reference

#include <qnoncontiguousbytedevice_p.h>

Inheritance diagram for QByteDeviceWrappingIoDevice:
QIODevice QObject

Public Functions

virtual bool atEnd () const
 Returns true if the current read and write position is at the end of the device (i.e. More...
 
virtual bool isSequential () const
 Returns true if this device is sequential; otherwise returns false. More...
 
 QByteDeviceWrappingIoDevice (QNonContiguousByteDevice *bd)
 
virtual bool reset ()
 Seeks to the start of input for random-access devices. More...
 
virtual qint64 size () const
 For open random-access devices, this function returns the size of the device. More...
 
 ~QByteDeviceWrappingIoDevice ()
 
- 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...
 
virtual bool canReadLine () const
 Returns true if a complete line of data can be read from the device; otherwise returns false. More...
 
virtual void close ()
 First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. 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...
 
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...
 
virtual bool open (OpenMode mode)
 Opens the device and sets its OpenMode to mode. 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...
 
virtual qint64 pos () const
 For random-access devices, this function returns the position that data is written to or read from. 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 seek (qint64 pos)
 For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. 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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

virtual qint64 readData (char *data, qint64 maxSize)
 Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred. More...
 
virtual qint64 writeData (const char *data, qint64 maxSize)
 Writes up to maxSize bytes from data to the device. 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 connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () 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...
 

Protected Variables

QNonContiguousByteDevicebyteDevice
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

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...
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 172 of file qnoncontiguousbytedevice_p.h.

Constructors and Destructors

◆ QByteDeviceWrappingIoDevice()

QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice ( QNonContiguousByteDevice bd)

Definition at line 436 of file qnoncontiguousbytedevice.cpp.

Referenced by QNonContiguousByteDeviceFactory::wrap().

436  : QIODevice((QObject*)0)
437 {
438  byteDevice = bd;
440 
441  open(ReadOnly);
442 }
QNonContiguousByteDevice * byteDevice
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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 rece...
Definition: qobject.cpp:2580
QIODevice()
Constructs a QIODevice object.
Definition: qiodevice.cpp:390
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
void readyRead()
This signal is emitted once every time new data is available for reading from the device...

◆ ~QByteDeviceWrappingIoDevice()

QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice ( )

Definition at line 444 of file qnoncontiguousbytedevice.cpp.

445 {
446 
447 }

Functions

◆ atEnd()

bool QByteDeviceWrappingIoDevice::atEnd ( ) const
virtual

Returns true if the current read and write position is at the end of the device (i.e.

there is no more data available for reading on 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 that generate data in direct response to you calling read() (e.g., /dev or /proc files on Unix and Mac OS X, or console input / stdin on all platforms).

See also
bytesAvailable(), read(), isSequential()

Reimplemented from QIODevice.

Definition at line 454 of file qnoncontiguousbytedevice.cpp.

455 {
456  return byteDevice->atEnd();
457 }
QNonContiguousByteDevice * byteDevice
virtual bool atEnd()=0
Returns true if everything has been read and the read pointer cannot be advanced anymore.

◆ isSequential()

bool QByteDeviceWrappingIoDevice::isSequential ( ) const
virtual

Returns true if this device is sequential; otherwise returns false.

Sequential devices, as opposed to a random-access devices, have no concept of a start, an end, a size, or a current position, and they do not support seeking. You can only read from the device when it reports that data is available. The most common example of a sequential device is a network socket. On Unix, special files such as /dev/zero and fifo pipes are sequential.

Regular files, on the other hand, do support random access. They have both a size and a current position, and they also support seeking backwards and forwards in the data stream. Regular files are non-sequential.

The QIODevice implementation returns false.

See also
bytesAvailable()

Reimplemented from QIODevice.

Definition at line 449 of file qnoncontiguousbytedevice.cpp.

Referenced by size().

450 {
451  return (byteDevice->size() == -1);
452 }
QNonContiguousByteDevice * byteDevice
virtual qint64 size()=0
Returns the size of the complete device or -1 if unknown.

◆ readData()

qint64 QByteDeviceWrappingIoDevice::readData ( char *  data,
qint64  maxSize 
)
protectedvirtual

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), this function returns -1.

This function is called by QIODevice. Reimplement this function when creating a subclass of QIODevice.

When reimplementing this function it is important that this function 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.

See also
read() readLine() writeData()

Implements QIODevice.

Definition at line 473 of file qnoncontiguousbytedevice.cpp.

474 {
475  qint64 len;
476  const char *readPointer = byteDevice->readPointer(maxSize, len);
477  if (len == -1)
478  return -1;
479 
480  memcpy(data, readPointer, len);
482  return len;
483 }
QNonContiguousByteDevice * byteDevice
virtual const char * readPointer(qint64 maximumLength, qint64 &len)=0
Return a byte pointer for at most maximumLength bytes of that device.
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
virtual bool advanceReadPointer(qint64 amount)=0
The old readPointer is invalid after this call.

◆ reset()

bool QByteDeviceWrappingIoDevice::reset ( )
virtual

Seeks to the start of input for random-access devices.

Returns true on success; otherwise returns false (for example, if the device is not open).

Note that when using a QTextStream on a QFile, calling reset() on the QFile will not have the expected result because QTextStream buffers the file. Use the QTextStream::seek() function instead.

See also
seek()

Reimplemented from QIODevice.

Definition at line 459 of file qnoncontiguousbytedevice.cpp.

460 {
461  return byteDevice->reset();
462 }
virtual bool reset()=0
Moves the internal read pointer back to the beginning.
QNonContiguousByteDevice * byteDevice

◆ size()

qint64 QByteDeviceWrappingIoDevice::size ( ) const
virtual

For open random-access devices, this function 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.

See also
isSequential(), pos()

Reimplemented from QIODevice.

Definition at line 464 of file qnoncontiguousbytedevice.cpp.

465 {
466  if (isSequential())
467  return 0;
468 
469  return byteDevice->size();
470 }
QNonContiguousByteDevice * byteDevice
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual qint64 size()=0
Returns the size of the complete device or -1 if unknown.

◆ writeData()

qint64 QByteDeviceWrappingIoDevice::writeData ( const char *  data,
qint64  maxSize 
)
protectedvirtual

Writes up to maxSize bytes from data to the device.

Returns the number of bytes written, or -1 if an error occurred.

This function is called by QIODevice. Reimplement this function when creating a subclass of QIODevice.

When reimplementing this function it is important that this function 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.

See also
read() write()

Implements QIODevice.

Definition at line 485 of file qnoncontiguousbytedevice.cpp.

486 {
487  Q_UNUSED(data);
488  Q_UNUSED(maxSize);
489  return -1;
490 }
static const char * data(const QByteArray &arr)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Properties

◆ byteDevice

QNonContiguousByteDevice* QByteDeviceWrappingIoDevice::byteDevice
protected

The documentation for this class was generated from the following files: