CopperSpice API  1.9.1
QIODevice Class Referenceabstract

The QIODevice class is the base interface class of all I/O devices. More...

Inheritance diagram for QIODevice:
QObject QAbstractSocket QBuffer QFileDevice QLocalSocket QNetworkReply QProcess QTcpSocket QUdpSocket QFile QSaveFile QSslSocket QTemporaryFile

Public Typedefs

using OpenMode = QFlags< OpenModeFlag >
 

Public Types

enum  OpenModeFlag
 

Public Signals

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 Methods

 QIODevice ()
 
 QIODevice (QObject *parent)
 
virtual ~QIODevice ()
 
virtual bool atEnd () const
 
virtual qint64 bytesAvailable () const
 
virtual qint64 bytesToWrite () const
 
virtual bool canReadLine () const
 
virtual void close ()
 
QString errorString () const
 
bool getChar (char *c)
 
bool isOpen () const
 
bool isReadable () const
 
virtual bool isSequential () const
 
bool isTextModeEnabled () const
 
bool isWritable () const
 
virtual bool open (OpenMode mode)
 
OpenMode openMode () const
 
qint64 peek (char *data, qint64 maxSize)
 
QByteArray peek (qint64 maxSize)
 
virtual qint64 pos () const
 
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 ()
 
virtual bool seek (qint64 pos)
 
void setTextModeEnabled (bool enabled)
 
virtual qint64 size () const
 
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< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, 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 QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
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)
 
QThreadthread () const
 

Protected Methods

virtual qint64 readData (char *data, qint64 maxSize) = 0
 
virtual qint64 readLineData (char *data, qint64 maxSize)
 
void setErrorString (const QString &errorString)
 
void setOpenMode (OpenMode openMode)
 
virtual qint64 writeData (const char *data, qint64 maxSize) = 0
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
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 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 QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QIODevice class is the base interface class of all I/O devices.

QIODevice provides both a common implementation and an abstract interface for devices that support reading and writing of blocks of data, such as QFile, QBuffer and QTcpSocket. QIODevice is abstract and can not be instantiated, but it is common to use the interface it defines to provide device-independent I/O features. For example, the CopperSpice XML classes operate on a QIODevice pointer, allowing them to be used with various devices (such as files and buffers).

Before accessing the device, open() must be called to set the correct OpenMode (such as ReadOnly or ReadWrite). You can then write to the device with write() or putChar(), and read by calling either read(), readLine(), or readAll(). Call close() when you are done with the device.

QIODevice distinguishes between two types of devices: random-access devices and sequential devices.

  • Random-access devices support seeking to arbitrary positions using seek(). The current position in the file is available by calling pos(). QFile and QBuffer are examples of random-access devices.
  • Sequential devices do not support seeking to arbitrary positions. The data must be read in one pass. The methods pos() and size() do not work for sequential devices. QTcpSocket and QProcess are examples of sequential devices.

You can use isSequential() to determine the type of device.

QIODevice emits readyRead() when new data is available for reading; for example, if new data has arrived on the network or if additional data is appended to a file that you are reading from. You can call bytesAvailable() to determine the number of bytes that are currently available for reading. It is common to use bytesAvailable() together with the readyRead() signal when programming with asynchronous devices such as QTcpSocket, where fragments of data can arrive at arbitrary points in time. QIODevice emits the bytesWritten() signal every time a payload of data has been written to the device. Use bytesToWrite() to determine the current amount of data waiting to be written.

Certain subclasses of QIODevice, such as QTcpSocket and QProcess, are asynchronous. This means that I/O functions such as write() or read() always return immediately, while communication with the device itself may happen when control goes back to the event loop. QIODevice provides functions that allow you to force these operations to be performed immediately, while blocking the calling thread and without entering the event loop. This allows QIODevice subclasses to be used without an event loop, or in a separate thread:

waitForReadyRead()
suspends operation in the calling thread until new data is available for reading.
waitForBytesWritten()
suspends operation in the calling thread until one payload of data has been written to the device.
waitFor...()
Subclasses of QIODevice implement blocking functions for device-specific operations. For example, QProcess has a method called waitForStarted() which suspends operation in the calling thread until the process has started.

Calling these functions from the main, GUI thread, may cause your user interface to freeze.

QProcess gzip;
gzip.start("gzip", QStringList() << "-c");
if (! gzip.waitForStarted()) {
return false;
}
gzip.write("uncompressed data");
QByteArray compressed;
while (gzip.waitForReadyRead()) {
compressed += gzip.readAll();
}

By subclassing QIODevice, you can provide the same interface to your own I/O devices. Subclasses of QIODevice are only required to implement the protected readData() and writeData() functions. QIODevice uses these functions to implement all its functions, such as getChar(), readLine() and write(). QIODevice also handles access control for you, so you can safely assume that the device is opened in write mode if writeData() is called.

Some subclasses, such as QFile and QTcpSocket, are implemented using a memory buffer for intermediate storing of data. This reduces the number of required device accessing calls, which are often very slow. Buffering makes functions like getChar() and putChar() fast, as they can operate on the memory buffer instead of directly on the device itself. Certain I/O operations, however, do not work well with a buffer. For example, if several users open the same device and read it character by character, they may end up reading the same data when they meant to read a separate chunk each. For this reason, QIODevice allows you to bypass any buffering by passing the Unbuffered flag to open(). When subclassing QIODevice, remember to bypass any buffer you may use when the device is open in Unbuffered mode.

See also
QBuffer, QFile, QTcpSocket

Member Typedef Documentation

Typedef for QFlags<OpenModeFlag>. Refer to QIODevice::OpenModeFlag for documentation.

Member Enumeration Documentation

This enum is used with open() to describe the mode in which a device is opened. It is also returned by openMode().

Certain flags, such as Unbuffered and Truncate, are meaningless when used with some subclasses. Some of these restrictions are implied by the type of device that is represented by a subclass. In other cases, the restriction may be due to the implementation, or may be imposed by the underlying platform. For example, QTcpSocket does not support Unbuffered mode, and limitations in the native API prevent QFile from supporting Unbuffered on Windows.

ConstantValueDescription
QIODevice::NotOpen0x0000Not open.
QIODevice::ReadOnly0x0001Open for reading.
QIODevice::WriteOnly0x0002Open for writing.
QIODevice::ReadWriteReadOnly | WriteOnlyOpen for reading and writing.
QIODevice::Append0x0004 Opened in append mode, so that all data is written to the end of the file.
QIODevice::Truncate0x0008 If possible the device is truncated before it is opened. All earlier contents of the device are lost.
QIODevice::Text0x0010 When reading the end-of-line terminators are translated to '\n'. When writing the end-of-line terminators are translated to the local encoding. For example '\r\n' for Win32.
QIODevice::Unbuffered0x0020Any buffer in the device is bypassed.

Constructor & Destructor Documentation

QIODevice::QIODevice ( )

Constructs a QIODevice object.

QIODevice::QIODevice ( QObject parent)
explicit

Constructs a QIODevice object with the given parent.

QIODevice::~QIODevice ( )
virtual

The destructor is virtual, and QIODevice is an abstract base class. This destructor does not call close(), but the subclass destructor might. If you are in doubt, call close() before destroying the QIODevice.

Method Documentation

void QIODevice::aboutToClose ( )
signal

This signal is emitted when the device is about to close. Connect this signal if you have operations that need to be performed before the device closes (e.g., if you have data in a separate buffer that needs to be written to the device).

bool QIODevice::atEnd ( ) const
virtual

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().

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

Reimplemented in QAbstractSocket::atEnd(), QProcess::atEnd(), QSslSocket::atEnd(), QFileDevice::atEnd(), QBuffer::atEnd()

qint64 QIODevice::bytesAvailable ( ) const
virtual

Returns the number of bytes that are available for reading. This method is commonly used with sequential devices to determine the number of bytes to allocate in a buffer before reading. Subclasses that reimplement this method must call the base implementation in order to include the size of the QIODevice buffer.

qint64 CustomDevice::bytesAvailable() const {
return buffer.size() + QIODevice::bytesAvailable();
}
See also
bytesToWrite(), readyRead(), isSequential()

Reimplemented in QProcess::bytesAvailable(), QAbstractSocket::bytesAvailable(), QSslSocket::bytesAvailable(), QLocalSocket::bytesAvailable()

qint64 QIODevice::bytesToWrite ( ) const
virtual

For buffered devices, this method returns the number of bytes waiting to be written. For devices with no buffer, this method returns 0.

See also
bytesAvailable(), bytesWritten(), isSequential()

Reimplemented in QProcess::bytesToWrite(), QAbstractSocket::bytesToWrite(), QSslSocket::bytesToWrite(), QLocalSocket::bytesToWrite()

void QIODevice::bytesWritten ( qint64  bytes)
signal

This signal is emitted every time a payload of data has been written to the device. The bytes argument is set to the number of bytes that were written in this payload.

This methods is not emitted recursively. If you reenter the event loop or call waitForBytesWritten() inside a slot connected to the bytesWritten() signal, the signal will not be re-emitted (although waitForBytesWritten() may still return true).

See also
readyRead()
bool QIODevice::canReadLine ( ) const
virtual

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.

bool CustomDevice::canReadLine() const {
return buffer.contains('\n') || QIODevice::canReadLine();
}
See also
readyRead(), readLine()

Reimplemented in QProcess::canReadLine(), QAbstractSocket::canReadLine(), QSslSocket::canReadLine(), QLocalSocket::canReadLine(), QBuffer::canReadLine()

void QIODevice::close ( )
virtual

First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. The error string is also reset.

See also
setOpenMode(), OpenMode

Reimplemented in QAbstractSocket::close(), QProcess::close(), QSslSocket::close(), QNetworkReply::close(), QLocalSocket::close(), QFileDevice::close(), QBuffer::close()

QString QIODevice::errorString ( ) const

Returns a human-readable description of the last device error that occurred.

See also
setErrorString()
bool QIODevice::getChar ( char *  c)

Reads one character from the device and stores it in c. If c is 0, the character is discarded. Returns true on success, otherwise returns false.

See also
read(), putChar(), ungetChar()
bool QIODevice::isOpen ( ) const

Returns true if the device is open, otherwise returns false. A device is open if it can be read from and/or written to. By default, this method returns false if openMode() returns NotOpen.

See also
openMode(), OpenMode
bool QIODevice::isReadable ( ) const

Returns true if data can be read from the device, otherwise returns false. Use bytesAvailable() to determine how many bytes can be read. This method checks if the OpenMode of the device contains the ReadOnly flag.

See also
openMode(), OpenMode
bool QIODevice::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 in QAbstractSocket::isSequential(), QProcess::isSequential(), QNetworkReply::isSequential(), QLocalSocket::isSequential(), QFileDevice::isSequential()

bool QIODevice::isTextModeEnabled ( ) const

Returns true if the Text flag is enabled, otherwise returns false.

See also
setTextModeEnabled()
bool QIODevice::isWritable ( ) const

Returns true if data can be written to the device, otherwise returns false. This method checks if the OpenMode of the device contains the Write Only flag.

See also
openMode(), OpenMode
bool QIODevice::open ( OpenMode  mode)
virtual

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.

See also
openMode(), OpenMode

Reimplemented in QLocalSocket::open(), QBuffer::open(), QProcess::open(), QFile::open(), QSaveFile::open(), QTemporaryFile::open()

OpenMode QIODevice::openMode ( ) const

Returns the mode in which the device has been opened, for example ReadOnly or WriteOnly.

See also
setOpenMode(), OpenMode
qint64 QIODevice::peek ( char *  data,
qint64  maxSize 
)

Reads at most maxSize bytes from the device into data, without side effects (i.e., if you call read() after peek(), you will get the same data). Returns the number of bytes read. If an error occurs, such as when attempting to peek a device opened in WriteOnly mode, this method returns -1.

The value of 0 is returned when no more data is available for reading.

bool isExeFile(QFile *file) {
char buf[2];
if (file->peek(buf, sizeof(buf)) == sizeof(buf)) {
return (buf[0] == 'M' && buf[1] == 'Z');
}
return false;
}
See also
read()
QByteArray QIODevice::peek ( qint64  maxSize)

Peeks at most maxSize bytes from the device, returning the data peeked as a QByteArray.

bool isExeFile(QFile *file) {
return file->peek(2) == "MZ";
}

This method has no way of reporting errors. Returning an empty QByteArray() can mean either that no data was currently available for peeking, or that an error occurred.

See also
read()
qint64 QIODevice::pos ( ) const
virtual

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.

See also
isSequential(), seek()

Reimplemented in QFileDevice::pos(), QBuffer::pos()

bool QIODevice::putChar ( char  c)

Writes the character c to the device. Returns true on success, otherwise returns false.

See also
write(), getChar(), ungetChar()
qint64 QIODevice::read ( char *  data,
qint64  maxSize 
)

Reads at most maxSize bytes from the device into data, and returns the number of bytes read. If an error occurs, such as when attempting to read from a device opened in WriteOnly mode, this method returns -1.

Value of 0 is returned when no more data is available for reading. However, reading past the end of the stream is considered an error, so this method returns -1 in those cases (that is, reading on a closed socket or after a process has died).

See also
readData(), readLine(), write()
QByteArray QIODevice::read ( qint64  maxSize)

Reads at most maxSize bytes from the device, and returns the data read as a QByteArray. This method has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.

QByteArray QIODevice::readAll ( )

Reads all available data from the device, and returns it as a QByteArray.

This method has no way of reporting errors, returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.

void QIODevice::readChannelFinished ( )
signal

This signal is emitted when the input (reading) stream is closed in this device. It is emitted as soon as the closing is detected, which means that there might still be data available for reading with read().

See also
atEnd(), read()
qint64 QIODevice::readData ( char *  data,
qint64  maxSize 
)
protectedpure virtual

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.

See also
read(), readLine(), writeData()

Implemented in QBuffer::readData(), QFileDevice::readData(), QAbstractSocket::readData(), QProcess::readData(), QSslSocket::readData(), QLocalSocket::readData()

qint64 QIODevice::readLine ( char *  data,
qint64  maxSize 
)

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. If a line could not be read but no error occurred, this method returns 0. If an error occurs, this method returns the length of what could be read, or -1 if nothing was read.

A terminating '\0' byte is always appended to data, so maxSize must be larger than 1. Data is read until either of the following conditions are met.

  • The first '\n' character is read.
  • maxSize - 1 bytes are read.
  • The end of the device data is detected.

For example, the following code reads a line of characters from a file:

QFile file("box.txt");
if (file.open(QFile::ReadOnly)) {
char buf[1024];
qint64 lineLength = file.readLine(buf, sizeof(buf));
if (lineLength != -1) {
// the line is available in buf
}
}

The newline character ('\n') is included in the buffer. If a newline is not encountered before maxSize - 1 bytes are read, a newline will not be inserted into the buffer. On windows newline characters are replaced with '\n'.

This method calls readLineData(), which is implemented using repeated calls to getChar(). You can provide a more efficient implementation by reimplementing readLineData() in your own subclass.

See also
getChar(), read(), write()
QByteArray QIODevice::readLine ( qint64  maxSize = 0)

Reads a line from the device, but no more than maxSize characters and returns the result as a QByteArray.

This method has no way of reporting errors. Returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.

qint64 QIODevice::readLineData ( char *  data,
qint64  maxSize 
)
protectedvirtual

Reads up to maxSize characters into data and returns the number of characters read. This method is called by readLine(), and provides its base implementation, using getChar(). Buffered devices can improve the performance of readLine() by reimplementing this method.

The readLine() method appends a '\0' byte to data, readLineData() does not need to do this.

If you reimplement this method, be careful to return the correct value: it should return the number of bytes read in this line, including the terminating newline, or 0 if there is no line to be read at this point. If an error occurs, it should return -1 if and only if no bytes were read. Reading past EOF is considered an error.

Reimplemented in QFileDevice::readLineData(), QAbstractSocket::readLineData()

void QIODevice::readyRead ( )
signal

This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.

readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true).

Note for developers implementing classes derived from QIODevice: you should always emit readyRead() when new data has arrived (do not emit it only because there's data still to be read in your buffers). Do not emit readyRead() in other conditions.

See also
bytesWritten()
bool QIODevice::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). 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() method instead.

See also
seek()
bool QIODevice::seek ( qint64  pos)
virtual

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.

See also
pos(), isSequential()

Reimplemented in QFileDevice::seek(), QBuffer::seek()

void QIODevice::setErrorString ( const QString errorString)
protected

Sets the human readable description of the last device error that occurred to errorString.

See also
errorString()
void QIODevice::setOpenMode ( OpenMode  openMode)
protected

Sets the OpenMode of the device to openMode. Call this method to set the open mode if the flags change after the device has been opened.

See also
openMode(), OpenMode
void QIODevice::setTextModeEnabled ( bool  enabled)

If enabled is true, this method sets the Text flag on the device, otherwise the Text flag is removed. This feature is useful for classes that provide custom end-of-line handling on a QIODevice.

The IO device should be opened before calling this method.

See also
isTextModeEnabled(), open(), setOpenMode()
qint64 QIODevice::size ( ) const
virtual

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.

See also
isSequential(), pos()

Reimplemented in QFile::size(), QFileDevice::size(), QBuffer::size()

void QIODevice::ungetChar ( char  c)

Puts the character c back into the device, and decrements the current position unless the position is 0. This method is usually called to "undo" a get Char() operation, such as when writing a backtracking parser. If c was not previously read from the device, the behavior is undefined.

bool QIODevice::waitForBytesWritten ( int  msecs)
virtual

For buffered devices, this method 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. If msecs is -1, This method will not time out. For unbuffered devices, it returns immediately.

Returns true if a payload of data was written to the device, otherwise returns false (i.e. if the operation timed out, or if an error occurred).

This method can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread. If called from within a slot connected to the bytesWritten() signal, bytesWritten() will not be re-emitted.

Reimplement this method to provide a blocking API for a custom device. The default implementation does nothing, and returns false.

Warning
Calling this method from the main (GUI) thread might cause your user interface to freeze.
See also
waitForReadyRead()

Reimplemented in QAbstractSocket::waitForBytesWritten(), QSslSocket::waitForBytesWritten(), QProcess::waitForBytesWritten(), QLocalSocket::waitForBytesWritten()

bool QIODevice::waitForReadyRead ( int  msecs)
virtual

Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this method will not time out. Returns true if new data is available for reading, otherwise returns false.

This method can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread. If called from within a slot connected to the readyRead() signal, readyRead() will not be reemitted.

Reimplement this method to provide a blocking API for a custom device. The default implementation does nothing, and returns false.

Warning
Calling this method from the main (GUI) thread might cause your user interface to freeze.
See also
waitForBytesWritten()

Reimplemented in QAbstractSocket::waitForReadyRead(), QSslSocket::waitForReadyRead(), QProcess::waitForReadyRead(), QLocalSocket::waitForReadyRead()

qint64 QIODevice::write ( const char *  data)

Writes data from a zero-terminated string of 8-bit characters to the device. Returns the number of bytes that were actually written, or -1 if an error occurred. This is equivalent to the following code.

QIODevice::write(data, qstrlen(data));
See also
read(), writeData()
qint64 QIODevice::write ( const char *  data,
qint64  maxSize 
)

Writes at most maxSize bytes of data from data to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.

See also
read(), writeData()
qint64 QIODevice::write ( const QByteArray data)
inline

Writes the content of data to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.

See also
read(), writeData()
qint64 QIODevice::writeData ( const char *  data,
qint64  maxSize 
)
protectedpure virtual

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.

See also
read(), write()

Implemented in QBuffer::writeData(), QFileDevice::writeData(), QAbstractSocket::writeData(), QProcess::writeData(), QSslSocket::writeData(), QNetworkReply::writeData(), QSaveFile::writeData(), QLocalSocket::writeData()