Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QIODevice Class Referenceabstract

\inmodule QtCore \reentrant More...

#include <qiodevice.h>

+ Inheritance diagram for QIODevice:
+ Collaboration diagram for QIODevice:

Signals

void readyRead ()
 This signal is emitted once every time new data is available for reading from the device's current read channel.
 
void channelReadyRead (int channel)
 
void bytesWritten (qint64 bytes)
 This signal is emitted every time a payload of data has been written to the device's current write channel.
 
void channelBytesWritten (int channel, qint64 bytes)
 
void aboutToClose ()
 This signal is emitted when the device is about to close.
 
void readChannelFinished ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QIODevice ()
 Constructs a QIODevice object.
 
 QIODevice (QObject *parent)
 Constructs a QIODevice object with the given parent.
 
virtual ~QIODevice ()
 The destructor is virtual, and QIODevice is an abstract base class.
 
QIODeviceBase::OpenMode openMode () const
 Returns the mode in which the device has been opened; i.e.
 
void setTextModeEnabled (bool enabled)
 If enabled is true, this function sets the \l Text flag on the device; otherwise the \l Text flag is removed.
 
bool isTextModeEnabled () const
 Returns true if the \l Text flag is enabled; otherwise returns false.
 
bool isOpen () const
 Returns true if the device is open; otherwise returns false.
 
bool isReadable () const
 Returns true if data can be read from the device; otherwise returns false.
 
bool isWritable () const
 Returns true if data can be written to the device; otherwise returns false.
 
virtual bool isSequential () const
 Returns true if this device is sequential; otherwise returns false.
 
int readChannelCount () const
 
int writeChannelCount () const
 
int currentReadChannel () const
 
void setCurrentReadChannel (int channel)
 
int currentWriteChannel () const
 
void setCurrentWriteChannel (int channel)
 
virtual bool open (QIODeviceBase::OpenMode mode)
 Opens the device and sets its OpenMode to mode.
 
virtual void close ()
 First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
 
virtual qint64 pos () const
 For random-access devices, this function returns the position that data is written to or read from.
 
virtual qint64 size () const
 For open random-access devices, this function returns the size of the device.
 
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.
 
virtual bool atEnd () const
 Returns true if the current read and write position is at the end of the device (i.e.
 
virtual bool reset ()
 Seeks to the start of input for random-access devices.
 
virtual qint64 bytesAvailable () const
 Returns the number of bytes that are available for reading.
 
virtual qint64 bytesToWrite () const
 For buffered devices, this function returns the number of bytes waiting to be written.
 
qint64 read (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
 
QByteArray read (qint64 maxlen)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads at most maxSize bytes from the device, and returns the data read as a QByteArray.
 
QByteArray readAll ()
 Reads all remaining data from the device, and returns it as a byte array.
 
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.
 
QByteArray readLine (qint64 maxlen=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a line from the device, but no more than maxSize characters, and returns the result as a byte array.
 
virtual bool canReadLine () const
 Returns true if a complete line of data can be read from the device; otherwise returns false.
 
void startTransaction ()
 
void commitTransaction ()
 
void rollbackTransaction ()
 
bool isTransactionStarted () const
 
qint64 write (const char *data, qint64 len)
 Writes at most maxSize bytes of data from data to the device.
 
qint64 write (const char *data)
 
qint64 write (const QByteArray &data)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes the content of data to the device.
 
qint64 peek (char *data, qint64 maxlen)
 
QByteArray peek (qint64 maxlen)
 
qint64 skip (qint64 maxSize)
 
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.
 
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.
 
void ungetChar (char c)
 Puts the character c back into the device, and decrements the current position unless the position is 0.
 
bool putChar (char c)
 Writes the character c to the device.
 
bool getChar (char *c)
 Reads one character from the device and stores it in c.
 
QString errorString () const
 Returns a human-readable description of the last device error that occurred.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) 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.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
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.
 

Protected Member Functions

 QIODevice (QIODevicePrivate &dd, QObject *parent=nullptr)
 
virtual qint64 readData (char *data, qint64 maxlen)=0
 Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred.
 
virtual qint64 readLineData (char *data, qint64 maxlen)
 Reads up to maxSize characters into data and returns the number of characters read.
 
virtual qint64 skipData (qint64 maxSize)
 
virtual qint64 writeData (const char *data, qint64 len)=0
 Writes up to maxSize bytes from data to the device.
 
void setOpenMode (QIODeviceBase::OpenMode openMode)
 Sets the OpenMode of the device to openMode.
 
void setErrorString (const QString &errorString)
 Sets the human readable description of the last device error that occurred to str.
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QIODeviceBase
 ~QIODeviceBase ()=default
 

Additional Inherited Members

- Public Types inherited from QIODeviceBase
enum  OpenModeFlag {
  NotOpen = 0x0000 , ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = ReadOnly | WriteOnly ,
  Append = 0x0004 , Truncate = 0x0008 , Text = 0x0010 , Unbuffered = 0x0020 ,
  NewOnly = 0x0040 , ExistingOnly = 0x0080
}
 This enum is used with QIODevice::open() to describe the mode in which a device is opened. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\inmodule QtCore \reentrant

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

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 cannot be instantiated, but it is common to use the interface it defines to provide device-independent I/O features. For example, Qt's 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.

\list

  • 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 don't support seeking to arbitrary positions. The data must be read in one pass. The functions pos() and size() don't work for sequential devices. QTcpSocket and QProcess are examples of sequential devices. \endlist

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's 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:

\list

  • waitForReadyRead() - This function suspends operation in the calling thread until new data is available for reading.
  • waitForBytesWritten() - This function 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 function called \l {QProcess::}{waitForStarted()} which suspends operation in the calling thread until the process has started. \endlist

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

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 convenience 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, don't 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.

Usually, the incoming data stream from an asynchronous device is fragmented, and chunks of data can arrive at arbitrary points in time. To handle incomplete reads of data structures, use the transaction mechanism implemented by QIODevice. See startTransaction() and related functions for more details.

Some sequential devices support communicating via multiple channels. These channels represent separate streams of data that have the property of independently sequenced delivery. Once the device is opened, you can determine the number of channels by calling the readChannelCount() and writeChannelCount() functions. To switch between channels, call setCurrentReadChannel() and setCurrentWriteChannel(), respectively. QIODevice also provides additional signals to handle asynchronous communication on a per-channel basis.

See also
QBuffer, QFile, QTcpSocket

Definition at line 27 of file qiodevice.h.

Constructor & Destructor Documentation

◆ QIODevice() [1/3]

QIODevice::QIODevice ( )

Constructs a QIODevice object.

Definition at line 422 of file qiodevice.cpp.

References className, file, QFile::fileName(), metaObject(), and qPrintable.

+ Here is the call graph for this function:

◆ QIODevice() [2/3]

QIODevice::QIODevice ( QObject * parent)
explicit

Constructs a QIODevice object with the given parent.

Definition at line 436 of file qiodevice.cpp.

References className, metaObject(), and QObject::parent().

+ Here is the call graph for this function:

◆ ~QIODevice()

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.

Definition at line 460 of file qiodevice.cpp.

◆ QIODevice() [3/3]

QIODevice::QIODevice ( QIODevicePrivate & dd,
QObject * parent = nullptr )
protected

Definition at line 447 of file qiodevice.cpp.

Member Function Documentation

◆ aboutToClose

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

Referenced by close().

+ Here is the caller graph for this function:

◆ atEnd()

bool QIODevice::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 \macos, or console input / stdin on all platforms).

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

Reimplemented in QBuffer, QFileDevice, QByteDeviceWrappingIoDevice, QHttpMultiPartIODevice, QSslSocket, QSoundEffectPrivate, and QAudioOutputStream.

Definition at line 910 of file qiodevice.cpp.

References bytesAvailable(), d, and QIODeviceBase::NotOpen.

Referenced by QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QNetworkReplyImplPrivate::_q_copyReadyRead(), QDataStream::atEnd(), QBuffer::atEnd(), QSslSocket::atEnd(), MFStream::IsEndOfStream(), QNmeaSatelliteSimulationReader::readAvailableData(), QNonContiguousByteDeviceIoDeviceImpl::readPointer(), QTextStreamPrivate::scan(), and QPulseAudioSink::streamUnderflowCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bytesAvailable()

qint64 QIODevice::bytesAvailable ( ) const
virtual

Returns the number of bytes that are available for reading.

This function is commonly used with sequential devices to determine the number of bytes to allocate in a buffer before reading.

Subclasses that reimplement this function must call the base implementation in order to include the size of the buffer of QIODevice. Example:

See also
bytesToWrite(), readyRead(), isSequential()

Reimplemented in QHttpMultiPartIODevice, QNetworkReplyDataImpl, QNetworkReplyFileImpl, QNetworkReplyHttpImpl, QNetworkReplyImpl, QNetworkReplyWasmImpl, QAbstractSocket, QLocalSocket, QSslSocket, QBluetoothSocket, QSoundEffectPrivate, QWaveDecoder, InputPrivate, OurSink, GStreamerInputPrivate, and QAudioOutputStream.

Definition at line 953 of file qiodevice.cpp.

References d, qMax(), and size().

Referenced by QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData(), QNetworkReplyImplPrivate::_q_bufferOutgoingData(), QNetworkReplyWasmImplPrivate::_q_bufferOutgoingData(), QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QPdfDocumentPrivate::_q_copyFromSequentialSourceDevice(), QNetworkReplyImplPrivate::_q_copyReadyRead(), QHttpProtocolHandler::_q_readyRead(), QHttpProtocolHandler::_q_receiveReply(), QPdfDocumentPrivate::_q_tryLoadingWithSizeFromContentHeader(), atEnd(), QFileDevice::atEnd(), QHttpPartPrivate::bytesAvailable(), QNetworkAccessCacheBackend::bytesAvailable(), QNetworkAccessFileBackend::bytesAvailable(), QNetworkReplyDataImpl::bytesAvailable(), QNetworkReplyFileImpl::bytesAvailable(), QNetworkReplyHttpImpl::bytesAvailable(), QNetworkReplyImpl::bytesAvailable(), QNetworkReplyWasmImpl::bytesAvailable(), QAbstractSocket::bytesAvailable(), QLocalSocket::bytesAvailable(), QBluetoothSocket::bytesAvailable(), QWaveDecoder::bytesAvailable(), InputPrivate::bytesAvailable(), QAndroidAudioSource::bytesReady(), ICOReader::iconAt(), QPdfDocumentPrivate::load(), QNmeaSatelliteInfoSourcePrivate::prepareSourceDevice(), QCborStreamReaderPrivate::preread(), processSentence(), QDataStream::readBytes(), QHttpProtocolHandler::sendRequest(), size(), QNmeaSatelliteInfoSourcePrivate::sourceDataClosed(), QNmeaPositionInfoSourcePrivate::startUpdates(), QNmeaSatelliteInfoSourcePrivate::startUpdates(), and while().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bytesToWrite()

qint64 QIODevice::bytesToWrite ( ) const
virtual

For buffered devices, this function returns the number of bytes waiting to be written.

For devices with no buffer, this function returns 0.

Subclasses that reimplement this function must call the base implementation in order to include the size of the buffer of QIODevice.

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

Reimplemented in QHttpMultiPartIODevice, QAbstractSocket, QLocalSocket, QSslSocket, and QBluetoothSocket.

Definition at line 970 of file qiodevice.cpp.

Referenced by QAbstractSocket::bytesToWrite(), and QHttpProtocolHandler::sendRequest().

+ Here is the caller graph for this function:

◆ bytesWritten

QIODevice::bytesWritten ( qint64 bytes)
signal

This signal is emitted every time a payload of data has been written to the device's current write channel.

The bytes argument is set to the number of bytes that were written in this payload.

bytesWritten() 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 reemitted (although waitForBytesWritten() may still return true).

See also
readyRead()

Referenced by QPacketProtocol::QPacketProtocol(), QHttpNetworkConnectionChannel::init(), is_tracked_signal(), and QCtfServer::run().

+ Here is the caller graph for this function:

◆ canReadLine()

bool QIODevice::canReadLine ( ) const
virtual

Returns true if a complete line of data can be read from the device; otherwise returns false.

Note that unbuffered devices, which have no way of determining what can be read, always return false.

This function is often called in conjunction with the readyRead() signal.

Subclasses that reimplement this function must call the base implementation in order to include the contents of the QIODevice's buffer. Example:

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

Reimplemented in QBuffer, QNetworkReplyHttpImpl, QLocalSocket, QSslSocket, and QBluetoothSocket.

Definition at line 1539 of file qiodevice.cpp.

References d, and Q_INT64_C.

Referenced by QBuffer::canReadLine(), QNetworkReplyHttpImpl::canReadLine(), QLocalSocket::canReadLine(), QSslSocket::canReadLine(), QBluetoothSocket::canReadLine(), QNmeaRealTimeReader::readAvailableData(), and QNmeaSatelliteRealTimeReader::readAvailableData().

+ Here is the caller graph for this function:

◆ channelBytesWritten

QIODevice::channelBytesWritten ( int channel,
qint64 bytes )
signal
Since
5.7

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, while channel is the channel they were written to. Unlike bytesWritten(), it is emitted regardless of the \l{currentWriteChannel()}{current write channel}.

channelBytesWritten() can be emitted recursively - even for the same channel.

See also
bytesWritten(), channelReadyRead()

◆ channelReadyRead

QIODevice::channelReadyRead ( int channel)
signal
Since
5.7

This signal is emitted when new data is available for reading from the device. The channel argument is set to the index of the read channel on which the data has arrived. Unlike readyRead(), it is emitted regardless of the \l{currentReadChannel()}{current read channel}.

channelReadyRead() can be emitted recursively - even for the same channel.

See also
readyRead(), channelBytesWritten()

◆ close()

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(), QIODeviceBase::OpenMode

Reimplemented in QBuffer, QFileDevice, QHttpMultiPartIODevice, QNetworkReply, QNetworkReplyDataImpl, QNetworkReplyFileImpl, QNetworkReplyHttpImpl, QNetworkReplyImpl, QNetworkReplyWasmImpl, QAbstractSocket, QLocalSocket, QSctpSocket, QSslSocket, QBluetoothSocket, and QWaveDecoder.

Definition at line 779 of file qiodevice.cpp.

References aboutToClose(), d, emit, and QIODeviceBase::NotOpen.

Referenced by QWasmMediaRecorder::~QWasmMediaRecorder(), QXmlStreamStrategy::~QXmlStreamStrategy(), QZipWriter::addFile(), QZipReader::close(), QZipWriter::close(), QBuffer::close(), QFileDevice::close(), QHttpMultiPartIODevice::close(), QNetworkReply::close(), QAbstractSocket::close(), QLocalSocket::close(), QSctpSocket::close(), QSslSocket::close(), QWaveDecoder::close(), MFStream::Close(), QPdfPrintEnginePrivate::closePrintDevice(), QWasmAudioOutput::stop(), QQsbIODeviceCollection::unmap(), and QTextDocumentWriter::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commitTransaction()

void QIODevice::commitTransaction ( )
Since
5.7

Completes a read transaction.

For sequential devices, all data recorded in the internal buffer during the transaction will be discarded.

See also
startTransaction(), rollbackTransaction()

Definition at line 1582 of file qiodevice.cpp.

References checkWarnMessage(), and d.

Referenced by QDataStream::abortTransaction(), QDataStream::commitTransaction(), and QDataStream::rollbackTransaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentReadChannel()

int QIODevice::currentReadChannel ( ) const
Since
5.7

Returns the index of the current read channel.

See also
setCurrentReadChannel(), readChannelCount(), QProcess

Definition at line 626 of file qiodevice.cpp.

◆ currentWriteChannel()

int QIODevice::currentWriteChannel ( ) const
Since
5.7

Returns the index of the current write channel.

See also
setCurrentWriteChannel(), writeChannelCount()

Definition at line 690 of file qiodevice.cpp.

◆ errorString()

QString QIODevice::errorString ( ) const

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

See also
setErrorString()

Definition at line 2127 of file qiodevice.cpp.

References d, QT_TRANSLATE_NOOP, and tr.

Referenced by RouteHandler::RouteHandler(), QHttpNetworkConnectionChannel::_q_error(), QSslSocketPrivate::_q_errorSlot(), QGeoRoutingManagerEngineNokia::calculateRoute(), QImageWriterPrivate::canWriteHelper(), createProject(), createSymbolicLink(), dumpOutput(), QHttpNetworkConnectionPrivate::emitReplyError(), QHttpNetworkConnectionPrivate::errorDetail(), QRestReply::errorString(), QGeoTileFetcherNokia::fetchCopyrightsData(), QGeoTileFetcherNokia::fetchVersionData(), findPatternUnloaded(), QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(), QGeoTileFetcher::handleReply(), if(), QImageReaderPrivate::initHandler(), QQmlJSLinter::lintFile(), QQuickTextDocumentPrivate::load(), QSvgTinyDocument::load(), QMimeXMLProvider::load(), QDnsLookup::lookup(), QDeclarativeSearchResultModel::onContentUpdated(), QNetworkFile::open(), QNetworkAccessFileBackend::open(), openFile(), QCupsPrintEnginePrivate::openPrintDevice(), QDeclarativeGeoJsonData::openUrl(), Moc::parsePluginData(), patchQtCore(), QDeclarativeSearchResultModel::queryFinished(), QNetworkAccessFileBackend::read(), readGpuFeatures(), QQmlXmlListModel::reload(), QFile::rename(), QDnsLookupRunnable::run(), QNetworkReply::setError(), QTlsPrivate::TlsCryptographSchannel::transmit(), QDeclarativeGeoRouteModel::update(), updateFile(), updateFile(), QGeoRoutingManagerEngineNokia::updateRoute(), QNetworkAccessFileBackend::uploadReadyReadSlot(), verifyString(), RCCFileInfo::writeDataBlob(), QDtlsPrivateOpenSSL::writeDatagramEncrypted(), and QQuickTextDocumentPrivate::writeTo().

+ Here is the caller graph for this function:

◆ getChar()

bool QIODevice::getChar ( char * c)

Reads one character from the device and stores it in c.

If c is \nullptr, the character is discarded. Returns true on success; otherwise returns false.

See also
read(), putChar(), ungetChar()

Definition at line 1856 of file qiodevice.cpp.

References ch, and read().

Referenced by QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(), QTgaFile::readImage(), and readMultiByteInt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOpen()

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 function returns false if openMode() returns NotOpen.

See also
openMode(), QIODeviceBase::OpenMode

Definition at line 560 of file qiodevice.cpp.

References QIODeviceBase::NotOpen.

Referenced by QQsbIODeviceCollection::~QQsbIODeviceCollection(), QWasmMediaRecorder::~QWasmMediaRecorder(), QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QNetworkReplyImplPrivate::_q_copyReadyRead(), QZipWriterPrivate::addEntry(), QFileDevice::atEnd(), QBuffer::canReadLine(), QImageWriter::canWrite(), QImageWriterPrivate::canWriteHelper(), QPicturePrivate::checkFormat(), QFileDevice::close(), QWaveDecoder::close(), QHttpNetworkConnectionChannel::ensureConnection(), QQsbIODeviceCollection::extractEntry(), QFileDevice::handle(), QNetworkReplyHttpImplPrivate::initCacheSaveDevice(), QNetworkReplyImplPrivate::initCacheSaveDevice(), QImageReaderPrivate::initHandler(), QAbstractSocket::isValid(), QQsbIODeviceCollection::map(), QFile::open(), QFile::open(), QFile::open(), QIOPipe::open(), QLocalSocket::open(), QNmeaSatelliteInfoSourcePrivate::openSourceDevice(), QCacheUtils::readCookedMesh(), QMimeBinaryProvider::CacheFile::reload(), QFileDevice::resize(), QZipReaderPrivate::scanFiles(), QFileDevice::seek(), QBuffer::setBuffer(), QBuffer::setData(), QBuffer::setData(), QFile::setFileName(), MFAudioDecoderControl::setSourceDevice(), setTextModeEnabled(), QAndroidAudioDecoder::start(), AVFAudioDecoder::start(), QGstreamerAudioDecoder::start(), QTlsPrivate::TlsCryptographSchannel::transmit(), and QQsbIODeviceCollection::unmap().

+ Here is the caller graph for this function:

◆ isReadable()

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 is a convenience function which checks if the OpenMode of the device contains the ReadOnly flag.

See also
openMode(), OpenMode

Definition at line 574 of file qiodevice.cpp.

References openMode(), and QIODeviceBase::ReadOnly.

Referenced by QTgaFile::QTgaFile(), QICNSHandler::canRead(), QQsbIODeviceCollection::extractEntry(), QZipReader::isReadable(), open(), QSctpSocket::readDatagram(), setOpenMode(), QAbstractSocket::setSocketDescriptor(), MFAudioDecoderControl::setSourceDevice(), QAndroidAudioDecoder::start(), AVFAudioDecoder::start(), and QGstreamerAudioDecoder::start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSequential()

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.

See also
bytesAvailable()

Reimplemented in QDarwinAudioSinkDevice, QDarwinAudioSourceDevice, QFileDevice, QByteDeviceWrappingIoDevice, qstdweb::BlobIODevice, qstdweb::Uint8ArrayIODevice, QHttpMultiPartIODevice, QNetworkReply, QNetworkReplyDataImpl, QNetworkReplyFileImpl, QNetworkReplyHttpImpl, QNetworkReplyWasmImpl, QAbstractSocket, QLocalSocket, QBluetoothSocket, QSoundEffectPrivate, QWaveDecoder, QnxPushIODevice, InputPrivate, GStreamerInputPrivate, QAudioOutputStream, and QIOPipe.

Definition at line 485 of file qiodevice.cpp.

Referenced by QTgaFile::QTgaFile(), QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QNetworkReplyImplPrivate::_q_copyReadyRead(), QXbmHandler::canRead(), QDDSHandler::canRead(), QICNSHandler::canRead(), QTgaHandler::canRead(), ICOReader::canRead(), NS_IIOF_HELPERS::cbSkipForward(), QNetworkAccessManager::createRequest(), QTextStreamPrivate::fillReadBuffer(), MFStream::GetCapabilities(), QMoviePrivate::infoForFrame(), QQmlPreviewFileEngine::isSequential(), QWaveDecoder::isSequential(), QWbmpHandler::option(), QNonContiguousByteDeviceIoDeviceImpl::pos(), readLineData(), QNonContiguousByteDeviceIoDeviceImpl::readPointer(), QFFmpeg::seekQIODevice(), QNetworkReplyImplPrivate::setup(), QNetworkReplyWasmImplPrivate::setup(), QNonContiguousByteDeviceIoDeviceImpl::size(), QNmeaPositionInfoSourcePrivate::startUpdates(), and QNmeaSatelliteInfoSourcePrivate::startUpdates().

+ Here is the caller graph for this function:

◆ isTextModeEnabled()

bool QIODevice::isTextModeEnabled ( ) const

Returns true if the \l Text flag is enabled; otherwise returns false.

See also
setTextModeEnabled()

Definition at line 547 of file qiodevice.cpp.

References QIODeviceBase::Text.

Referenced by QTextStreamPrivate::fillReadBuffer(), and QTextStreamPrivate::flushWriteBuffer().

+ Here is the caller graph for this function:

◆ isTransactionStarted()

bool QIODevice::isTransactionStarted ( ) const
Since
5.7

Returns true if a transaction is in progress on the device, otherwise false.

See also
startTransaction()

Definition at line 1627 of file qiodevice.cpp.

Referenced by QDataStream::isDeviceTransactionStarted(), and QDataStream::skipRawData().

+ Here is the caller graph for this function:

◆ isWritable()

bool QIODevice::isWritable ( ) const

Returns true if data can be written to the device; otherwise returns false.

This is a convenience function which checks if the OpenMode of the device contains the WriteOnly flag.

See also
openMode(), OpenMode

Definition at line 588 of file qiodevice.cpp.

References openMode(), and QIODeviceBase::WriteOnly.

Referenced by QImageWriterPrivate::canWriteHelper(), QZipWriter::isWritable(), open(), QBuffer::seek(), setOpenMode(), QAbstractSocket::setSocketDescriptor(), QICNSHandler::write(), QTextDocumentWriter::write(), QTextOdfWriter::writeAll(), and QSctpSocket::writeDatagram().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open()

bool QIODevice::open ( QIODeviceBase::OpenMode mode)
virtual

Opens the device and sets its OpenMode to mode.

Returns true if successful; otherwise returns false. This function should be called from any reimplementations of open() or other functions that open the device.

See also
openMode(), QIODeviceBase::OpenMode

Reimplemented in qstdweb::BlobIODevice.

Definition at line 756 of file qiodevice.cpp.

References QIODeviceBase::Append, d, isReadable(), isWritable(), size(), and QIODevicePrivate::Unset.

Referenced by QFFmpeg::AudioSourceIO::AudioSourceIO(), QPdf::ByteStream::ByteStream(), QPdf::ByteStream::ByteStream(), NullDevice::NullDevice(), QAudioOutputStream::QAudioOutputStream(), QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(), QCborStreamWriter::QCborStreamWriter(), QDarwinAudioSinkDevice::QDarwinAudioSinkDevice(), QDarwinAudioSourceDevice::QDarwinAudioSourceDevice(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(), QQmlJSStreamWriter::QQmlJSStreamWriter(), QSoundEffectPrivate::QSoundEffectPrivate(), QWindowsAudioSink::QWindowsAudioSink(), QWindowsAudioSource::QWindowsAudioSource(), QZipWriterPrivate::addEntry(), QZipWriter::addFile(), QImageWriterPrivate::canWriteHelper(), QPdf::ByteStream::clear(), QAbstractSocket::connectToHost(), QSslSocket::connectToHost(), QLocalSocket::connectToServer(), QImageReaderPrivate::initHandler(), QQsbIODeviceCollection::map(), QFile::open(), QFile::open(), QFile::open(), QBuffer::open(), QIOPipe::open(), qstdweb::Uint8ArrayIODevice::open(), QWaveDecoder::open(), qstdweb::BlobIODevice::open(), QNmeaSatelliteInfoSourcePrivate::openSourceDevice(), QZipReaderPrivate::scanFiles(), QLocalSocket::setSocketDescriptor(), QAbstractSocket::setSocketDescriptor(), QAlsaAudioSink::start(), QAlsaAudioSource::start(), QAndroidAudioSink::start(), QPulseAudioSink::start(), QPulseAudioSource::start(), QQnxAudioSink::start(), QQnxAudioSource::start(), QWasmAudioSink::start(), QWasmAudioSource::start(), QGStreamerAudioSink::start(), QGStreamerAudioSource::start(), QTextDocumentWriter::write(), and QTextOdfWriter::writeAll().

+ Here is the call graph for this function:

◆ openMode()

◆ peek() [1/2]

qint64 QIODevice::peek ( char * data,
qint64 maxSize )
Since
4.1

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

0 is returned when no more data is available for reading.

Example:

{
char buf[2];
if (file->peek(buf, sizeof(buf)) == sizeof(buf))
return (buf[0] == 'M' && buf[1] == 'Z');
return false;
}
See also
read()

Definition at line 1880 of file qiodevice.cpp.

References CHECK_MAXLEN, CHECK_READABLE, d, and peek().

Referenced by QHttpProtocolHandler::_q_readyRead(), QTextureFileReader::canRead(), QBmpHandler::canRead(), QPngHandler::canRead(), QXpmHandler::canRead(), QGifHandler::canRead(), QJpegHandler::canRead(), QDDSHandler::canRead(), QICNSHandler::canRead(), QMngHandler::canRead(), QWebpHandler::canRead(), QPdfIOHandler::canRead(), QPpmHandler::canRead(), QMacHeifHandler::canRead(), QMacJp2Handler::canRead(), QJp2Handler::canRead(), QSslServerPrivate::checkClientHelloAndContinue(), QHttpNetworkReplyPrivate::getChunkSize(), isExeFile(), peek(), QSslSocketPrivate::peek(), peek(), QSslSocketPrivate::peek(), QCborStreamReaderPrivate::preread(), and QNetworkAccessFileBackend::uploadReadyReadSlot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ peek() [2/2]

QByteArray QIODevice::peek ( qint64 maxSize)
Since
4.1 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Example:

{
return file->peek(2) == "MZ";
}
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition qfile.cpp:904
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,...
qint64 peek(char *data, qint64 maxlen)
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false.
GLenum GLuint buffer
GLenum GLuint GLenum GLsizei const GLchar * buf
bool isExeFile(QFile *file)
[3]
QProcess gzip
[0]
QByteArray compressed

This function 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()

Definition at line 1907 of file qiodevice.cpp.

References CHECK_MAXBYTEARRAYSIZE, CHECK_MAXLEN, CHECK_READABLE, d, peek(), and QByteArray().

+ Here is the call graph for this function:

◆ pos()

qint64 QIODevice::pos ( ) const
virtual

For random-access devices, this function 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 function is not necessary. When subclassing QIODevice, use QIODevice::seek() to notify QIODevice about changes in the device position.

See also
isSequential(), seek()

Reimplemented in QBuffer, QFileDevice, QWaveDecoder, and QAudioOutputStream.

Definition at line 814 of file qiodevice.cpp.

References d.

Referenced by QMovie::QMovie(), QTgaFile::QTgaFile(), QQsbIODeviceCollection::addEntry(), QZipWriterPrivate::addEntry(), QXbmHandler::canRead(), QTgaHandler::canRead(), ICOReader::canRead(), NS_IIOF_HELPERS::cbSkipForward(), QZipWriter::close(), QTextStreamPrivate::consume(), QCborStreamReader::currentOffset(), QZipReader::fileData(), MFStream::GetCurrentPosition(), QPdf::ByteStream::operator<<(), QWbmpHandler::option(), RCCResourceLibrary::output(), QBuffer::pos(), QFileDevice::pos(), QNonContiguousByteDeviceIoDeviceImpl::pos(), QWaveDecoder::pos(), qstdweb::BlobIODevice::readData(), qstdweb::Uint8ArrayIODevice::readData(), QMoviePrivate::reset(), QTextStreamPrivate::resetReadBuffer(), MFStream::Seek(), seek(), qstdweb::BlobIODevice::seek(), qstdweb::Uint8ArrayIODevice::seek(), QFFmpeg::seekQIODevice(), and qstdweb::Uint8ArrayIODevice::writeData().

+ Here is the caller graph for this function:

◆ putChar()

bool QIODevice::putChar ( char c)

Writes the character c to the device.

Returns true on success; otherwise returns false.

See also
write(), getChar(), ungetChar()

Definition at line 1808 of file qiodevice.cpp.

Referenced by QDataStream::operator<<(), RCCResourceLibrary::output(), and writeMultiByteInt().

+ Here is the caller graph for this function:

◆ read() [1/2]

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

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 function returns -1 in those cases (that is, reading on a closed socket or after a process has died).

See also
readData(), readLine(), write()

Definition at line 988 of file qiodevice.cpp.

References CHECK_MAXLEN, CHECK_READABLE, d, debugBinaryString(), QtMiscUtils::isAsciiPrintable(), read(), readData(), and QIODeviceBase::Text.

Referenced by QTgaFile::QTgaFile(), QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData(), QNetworkReplyImplPrivate::_q_bufferOutgoingData(), QNetworkReplyWasmImplPrivate::_q_bufferOutgoingData(), QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QPdfDocumentPrivate::_q_copyFromSequentialSourceDevice(), QNetworkReplyImplPrivate::_q_copyReadyRead(), NS_IIOF_HELPERS::cbGetBytes(), NS_IIOF_HELPERS::cbSkipForward(), QSocks5PasswordAuthenticator::continueAuthenticate(), QFile::copy(), QTranslatorPrivate::do_load(), QZipReader::fileData(), QTextStreamPrivate::fillReadBuffer(), findPatternUnloaded(), getChar(), QHttpNetworkReplyPrivate::getChunkSize(), ICOReader::iconAt(), isTzFile(), MFStream::Read(), read(), QNetworkAccessCacheBackend::read(), QNetworkAccessFileBackend::read(), QQmlPreviewFileEngine::read(), QGifHandler::read(), read(), ResourceIOStream::Read(), readAll(), readBMPInfoHeader(), QHttpNetworkReplyPrivate::readBodyFast(), QHttpNetworkReplyPrivate::readBodyVeryFast(), QFileDevice::readData(), QWaveDecoder::readData(), QHttpPartPrivate::readData(), QBluetoothSocketPrivateBluezDBus::readData(), QPacketProtocolPrivate::readFromDevice(), QHttpNetworkReplyPrivate::readHeader(), readIconDir(), readIconDirEntry(), readLineData(), QFileDevice::readLineData(), QNonContiguousByteDeviceIoDeviceImpl::readPointer(), QHttpNetworkReplyPrivate::readReplyBodyChunked(), QHttpNetworkReplyPrivate::readReplyBodyRaw(), QHttpNetworkReplyPrivate::readStatus(), QCborStreamReaderPrivate::readStringChunk_byte(), QCborStreamReaderPrivate::readStringChunk_unicode(), readWBMPData(), readWBMPHeader(), QFile::rename(), QZipReaderPrivate::scanFiles(), QMediaPlayerPrivate::setMedia(), QAndroidAudioSink::start(), test_tcpwait(), ungetChar(), and QWasmAudioSinkDevice::writeData().

+ Here is the call graph for this function:

◆ read() [2/2]

QByteArray QIODevice::read ( qint64 maxSize)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads at most maxSize bytes from the device, and returns the data read as a QByteArray.

This function 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.

Definition at line 1179 of file qiodevice.cpp.

References CHECK_MAXBYTEARRAYSIZE, CHECK_MAXLEN, CHECK_READABLE, d, read(), readData(), and QIODeviceBase::Text.

+ Here is the call graph for this function:

◆ readAll()

QByteArray QIODevice::readAll ( )

Reads all remaining data from the device, and returns it as a byte array.

This function 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. This function also has no way of indicating that more data may have been available and couldn't be read.

Definition at line 1226 of file qiodevice.cpp.

References CHECK_READABLE, d, QByteArray::max_size(), Q_INT64_C, qMax(), read(), and size().

Referenced by QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), QWindowsDirectWriteFontDatabase::addApplicationFont(), QZipWriter::addFile(), QOpenGLShader::compileSourceFile(), QGeoTileFetcherNokia::copyrightsFetched(), QNetworkDiskCache::data(), QNetworkReplyWasmImplPrivate::doSendRequest(), FontProvider::fetchFont(), QSslCertificate::fromPath(), QFreetypeFace::getFace(), QGeoFileTileCache::getFromDisk(), QGeoFileTileCacheOsm::getFromOfflineStorage(), QFileDialog::getOpenFileContent(), getRequestedDisplays(), QQmlSslKey::getSslKey(), gradleBuildFlags(), QQmlJSLinter::lintFile(), QQuickTextDocumentPrivate::load(), QDefaultOutputMapping::load(), QGtk3Json::load(), QPicture::load(), QQmlFile::load(), QQmlFile::load(), QKmsScreenConfig::loadConfig(), QRawFont::loadFromFile(), moduleFromJsonFile(), TileProvider::onNetworkReplyFinished(), MainWindow::openFile(), QDeclarativeGeoJsonData::openUrl(), QQmlJSTypeReader::operator()(), parseMountInfo(), Moc::parsePluginData(), patchQtCore(), QSvgHandler::processingInstruction(), QQmlTypeLoader::qmldirContent(), QAstcHandler::read(), QKtxHandler::read(), QPkmHandler::read(), Jpeg2000JasperReader::read(), QRestReply::readBody(), readGpuFeatures(), readGradleProperties(), readInputFile(), QRestReply::readJson(), readOrMapFile(), QRestReply::readText(), readTranslationsCatalogs(), QQmlXmlListModel::reload(), QSslSocket::setLocalCertificate(), QSslSocket::setPrivateKey(), QNetworkReplyImplPrivate::setup(), QNmeaPositionInfoSourcePrivate::startUpdates(), QNmeaSatelliteInfoSourcePrivate::startUpdates(), QWasmIDBSettingsPrivate::sync(), updateFile(), QGeoTileFetcherNokia::versionFetched(), RCCFileInfo::writeDataBlob(), and QTextOdfWriter::writeInlineCharacter().

+ Here is the call graph for this function:

◆ readChannelCount()

int QIODevice::readChannelCount ( ) const
Since
5.7

Returns the number of available read channels if the device is open; otherwise returns 0.

See also
writeChannelCount(), QProcess

Definition at line 601 of file qiodevice.cpp.

Referenced by QSslSocketPrivate::_q_connectedSlot(), and if().

+ Here is the caller graph for this function:

◆ readChannelFinished

QIODevice::readChannelFinished ( )
signal
Since
4.4

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

Referenced by QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(), QAbstractSocket::disconnectFromHost(), and QNetworkAccessFileBackend::open().

+ Here is the caller graph for this function:

◆ readData()

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

This function might be called with a maxSize of 0, which can be used to perform post-reading operations.

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

Implemented in QNetworkReplyHttpImpl, QLocalSocket, SLIODevicePrivate, OutputPrivate, QFFmpeg::AudioSourceIO, QDarwinAudioSinkDevice, QDarwinAudioSourceDevice, QnxPushIODevice, AlsaOutputPrivate, AlsaInputPrivate, QSoundEffectPrivate, PulseOutputPrivate, PulseInputPrivate, InputPrivate, OurSink, GStreamerOutputPrivate, GStreamerInputPrivate, QAudioOutputStream, NullDevice, QBuffer, QFileDevice, QNetworkReplyDataImpl, QNetworkReplyFileImpl, QNetworkReplyImpl, QNetworkReplyWasmImpl, QAbstractSocket, QSctpSocket, QSslSocket, QWaveDecoder, QWasmAudioSinkDevice, QWasmAudioSourceDevice, QIOPipe, QByteDeviceWrappingIoDevice, qstdweb::BlobIODevice, qstdweb::Uint8ArrayIODevice, QHttpMultiPartIODevice, QLocalUnixSocket, and QBluetoothSocket.

Referenced by QSctpSocket::readData(), and QLocalUnixSocket::readData().

+ Here is the caller graph for this function:

◆ readLine() [1/2]

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

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.

If a line could not be read but no error occurred, this function returns 0. If an error occurs, this function 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:

\list

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

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

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'.

Note that on sequential devices, data may not be immediately available, which may result in a partial line being returned. By calling the canReadLine() function before reading, you can check whether a complete line (including the newline character) can be read.

This function 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(), canReadLine(), write()

Definition at line 1314 of file qiodevice.cpp.

References CHECK_LINEMAXLEN, CHECK_READABLE, d, debugBinaryString(), and readLine().

Referenced by QIBusPlatformInputContextPrivate::createConnection(), QBenchmarkValgrindUtils::extractResult(), QTextStreamPrivate::fillReadBuffer(), getLibraryProjectsInOutputFolder(), if(), QGeoFileTileCache::loadTiles(), lookupVendorIdInSystemDatabase(), noStream_snippet(), QNmeaSatelliteInfoSourcePrivate::processNmeaData(), processSentence(), quick_test_main_with_setup(), QNmeaRealTimeReader::readAvailableData(), readLine(), QQmlPreviewFileEngine::readLine(), readLine(), and QQmlJS::Dom::FileWriter::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readLine() [2/2]

QByteArray QIODevice::readLine ( qint64 maxSize = 0)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a line from the device, but no more than maxSize characters, and returns the result as a byte array.

This function 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.

Definition at line 1437 of file qiodevice.cpp.

References CHECK_LINEMAXLEN, CHECK_MAXBYTEARRAYSIZE, CHECK_READABLE, d, QByteArray::max_size(), qMin(), and readLine().

+ Here is the call graph for this function:

◆ readLineData()

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

Reads up to maxSize characters into data and returns the number of characters read.

This function is called by readLine(), and provides its base implementation, using getChar(). Buffered devices can improve the performance of readLine() by reimplementing this function.

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

If you reimplement this function, 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, QAbstractSocket, QSctpSocket, and QLocalSocket.

Definition at line 1498 of file qiodevice.cpp.

References d, isSequential(), and read().

Referenced by QFileDevice::readLineData(), QAbstractSocket::readLineData(), and QSctpSocket::readLineData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readyRead

QIODevice::readyRead ( )
signal

This signal is emitted once every time new data is available for reading from the device's current read channel.

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

Referenced by QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(), QDarwinAudioSourceDevice::QDarwinAudioSourceDevice(), QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(), QPacketProtocol::QPacketProtocol(), QTuioHandler::QTuioHandler(), QWasmAudioSource::QWasmAudioSource(), QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(), QHttpNetworkConnectionChannel::init(), QIOPipePrivate::initialize(), QSslServerPrivate::initializeHandshakeProcess(), is_tracked_signal(), DtlsServer::listen(), QWaveDecoder::open(), QCtfServer::run(), QAlsaAudioSink::start(), QAndroidAudioSink::start(), QPulseAudioSink::start(), QWindowsAudioSink::start(), AlsaInputPrivate::trigger(), PulseInputPrivate::trigger(), and InputPrivate::trigger().

+ Here is the caller graph for this function:

◆ reset()

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

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 in QByteDeviceWrappingIoDevice, and QHttpMultiPartIODevice.

Definition at line 933 of file qiodevice.cpp.

References seek().

Referenced by QNetworkReplyHttpImplPrivate::onRedirected(), QCborStreamReader::reset(), QHttpPartPrivate::reset(), QNonContiguousByteDeviceIoDeviceImpl::reset(), QHttpMultiPartIODevice::reset(), QMediaPlayerPrivate::setMedia(), and QPdf::ByteStream::stream().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rollbackTransaction()

void QIODevice::rollbackTransaction ( )
Since
5.7

Rolls back a read transaction.

Restores the input stream to the point of the startTransaction() call. This function is commonly used to rollback the transaction when an incomplete read was detected prior to committing the transaction.

See also
startTransaction(), commitTransaction()

Definition at line 1606 of file qiodevice.cpp.

References checkWarnMessage(), and d.

Referenced by QDataStream::commitTransaction(), and QDataStream::rollbackTransaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ seek()

bool QIODevice::seek ( qint64 pos)
virtual

For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred.

For sequential devices, the default behavior is to produce a warning 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.

See also
pos(), isSequential()

Reimplemented in QBuffer, QFileDevice, qstdweb::BlobIODevice, qstdweb::Uint8ArrayIODevice, and QWaveDecoder.

Definition at line 849 of file qiodevice.cpp.

References checkWarnMessage(), d, QIODeviceBase::NotOpen, pos(), and qWarning.

Referenced by QTgaFile::QTgaFile(), QZipWriterPrivate::addEntry(), QXbmHandler::canRead(), QTgaHandler::canRead(), ICOReader::canRead(), NS_IIOF_HELPERS::cbSkipForward(), QZipWriter::close(), QQsbIODeviceCollection::extractEntry(), QZipReader::fileData(), QPdfDocumentPrivate::fpdf_GetBlock(), ICOReader::iconAt(), QMoviePrivate::infoForFrame(), QFile::open(), QFile::open(), QWbmpHandler::option(), ICOReader::readIconEntry(), QTgaFile::readImage(), reset(), QNonContiguousByteDeviceIoDeviceImpl::reset(), QZipReaderPrivate::scanFiles(), MFStream::Seek(), QBuffer::seek(), QFileDevice::seek(), qstdweb::BlobIODevice::seek(), qstdweb::Uint8ArrayIODevice::seek(), QWaveDecoder::seek(), QFFmpeg::seekQIODevice(), MFStream::SetCurrentPosition(), skip(), QNmeaPositionInfoSourcePrivate::startUpdates(), QNmeaSatelliteInfoSourcePrivate::startUpdates(), and write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentReadChannel()

void QIODevice::setCurrentReadChannel ( int channel)
Since
5.7

Sets the current read channel of the QIODevice to the given channel. The current input channel is used by the functions read(), readAll(), readLine(), and getChar(). It also determines which channel triggers QIODevice to emit readyRead().

See also
currentReadChannel(), readChannelCount(), QProcess

Definition at line 641 of file qiodevice.cpp.

References channel, checkWarnMessage(), d, and qDebug.

+ Here is the call graph for this function:

◆ setCurrentWriteChannel()

void QIODevice::setCurrentWriteChannel ( int channel)
Since
5.7

Sets the current write channel of the QIODevice to the given channel. The current output channel is used by the functions write(), putChar(). It also determines which channel triggers QIODevice to emit bytesWritten().

See also
currentWriteChannel(), writeChannelCount()

Definition at line 705 of file qiodevice.cpp.

References channel, d, and qDebug.

◆ setErrorString()

void QIODevice::setErrorString ( const QString & str)
protected

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

See also
errorString()

Definition at line 2116 of file qiodevice.cpp.

References str.

Referenced by QLocalSocket::connectToServer(), QNetworkReply::setError(), and QLocalUnixSocket::setErrorString().

+ Here is the caller graph for this function:

◆ setOpenMode()

void QIODevice::setOpenMode ( QIODeviceBase::OpenMode openMode)
protected

Sets the OpenMode of the device to openMode.

Call this function to set the open mode if the flags change after the device has been opened.

See also
openMode(), OpenMode

Definition at line 508 of file qiodevice.cpp.

References d, isReadable(), isWritable(), openMode(), qMax(), and QIODevicePrivate::Unset.

Referenced by QBluetoothSocket::QBluetoothSocket(), QBluetoothSocket::QBluetoothSocket(), QBluetoothSocket::abort(), QBluetoothSocket::close(), and QSslSocket::setSocketDescriptor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTextModeEnabled()

void QIODevice::setTextModeEnabled ( bool enabled)

If enabled is true, this function sets the \l Text flag on the device; otherwise the \l 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 function.

See also
open(), setOpenMode()

Definition at line 529 of file qiodevice.cpp.

References checkWarnMessage(), d, isOpen(), and QIODeviceBase::Text.

Referenced by QTextStreamPrivate::fillReadBuffer(), and QTextStreamPrivate::flushWriteBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

qint64 QIODevice::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 in QBuffer, QFile, QFileDevice, QByteDeviceWrappingIoDevice, qstdweb::BlobIODevice, qstdweb::Uint8ArrayIODevice, QHttpMultiPartIODevice, QNetworkReplyDataImpl, QNetworkReplyFileImpl, QNetworkReplyHttpImpl, QNetworkReplyWasmImpl, QSoundEffectPrivate, QWaveDecoder, and QAudioOutputStream.

Definition at line 832 of file qiodevice.cpp.

References bytesAvailable().

Referenced by QTgaFile::QTgaFile(), QSslSocket::activeBackend(), QHttpMultiPartIODevice::atEnd(), bytesAvailable(), QHttpMultiPartIODevice::bytesAvailable(), QNetworkAccessManager::createRequest(), QQsbIODeviceCollection::extractEntry(), MFStream::GetLength(), QXdgNotificationInterface::getServerInformation(), QPdfDocumentPrivate::load(), QQmlTypeLoaderNetworkReplyProxy::manualFinished(), open(), QCborStreamReaderPrivate::preread(), qDBusReplyFill(), readAll(), QZipReaderPrivate::scanFiles(), QFFmpeg::seekQIODevice(), AVFMediaPlayer::setMedia(), QNetworkReply::setReadBufferSize(), QAbstractSocket::setReadBufferSize(), QSslSocket::setReadBufferSize(), QGstAppSource::setup(), QHttpPartPrivate::size(), QNonContiguousByteDeviceIoDeviceImpl::size(), QNetworkReplyHttpImpl::size(), QNetworkReplyWasmImpl::size(), QWaveDecoder::size(), skip(), QAbstractSocket::writeData(), and QWasmAudioSinkDevice::writeData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skip()

qint64 QIODevice::skip ( qint64 maxSize)
Since
5.10

Skips up to maxSize bytes from the device. Returns the number of bytes actually skipped, or -1 on error.

This function does not wait and only discards the data that is already available for reading.

If the device is opened in text mode, end-of-line terminators are translated to '
' symbols and count as a single byte identically to the read() and peek() behavior.

This function works for all devices, including sequential ones that cannot seek(). It is optimized to skip unwanted data after a peek() call.

For random-access devices, skip() can be used to seek forward from the current position. Negative maxSize values are not allowed.

See also
skipData(), peek(), seek(), read()

Definition at line 1939 of file qiodevice.cpp.

References CHECK_MAXLEN, CHECK_READABLE, d, Q_INT64_C, qMin(), readData(), seek(), size(), skip(), skipData(), and QIODeviceBase::Text.

Referenced by QCborStreamReaderPrivate::preread(), QCborStreamReaderPrivate::readStringChunk(), QCborStreamReaderPrivate::readStringChunk_byte(), skip(), QDataStream::skipRawData(), and QNetworkAccessFileBackend::uploadReadyReadSlot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipData()

qint64 QIODevice::skipData ( qint64 maxSize)
protectedvirtual
Since
6.0

Skips up to maxSize bytes from the device. Returns the number of bytes actually skipped, or -1 on error.

This function is called by QIODevice. Consider reimplementing it when creating a subclass of QIODevice.

The base implementation discards the data by reading into a dummy buffer. This is slow, but works for all types of devices. Subclasses can reimplement this function to improve on that.

See also
skip(), peek(), seek(), read()

Reimplemented in QAbstractSocket, QLocalSocket, and QSslSocket.

Definition at line 2044 of file qiodevice.cpp.

Referenced by skip(), and QAbstractSocket::skipData().

+ Here is the caller graph for this function:

◆ startTransaction()

void QIODevice::startTransaction ( )
Since
5.7

Starts a new read transaction on the device.

Defines a restorable point within the sequence of read operations. For sequential devices, read data will be duplicated internally to allow recovery in case of incomplete reads. For random-access devices, this function saves the current position. Call commitTransaction() or rollbackTransaction() to finish the transaction.

Note
Nesting transactions is not supported.
See also
commitTransaction(), rollbackTransaction()

Definition at line 1561 of file qiodevice.cpp.

References checkWarnMessage(), and d.

Referenced by QDataStream::startTransaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ungetChar()

void QIODevice::ungetChar ( char c)

Puts the character c back into the device, and decrements the current position unless the position is 0.

This function is usually called to "undo" a getChar() operation, such as when writing a backtracking parser.

If c was not previously read from the device, the behavior is undefined.

Note
This function is not available while a transaction is in progress.

Definition at line 1782 of file qiodevice.cpp.

References CHECK_READABLE, checkWarnMessage(), d, QtMiscUtils::isAsciiPrintable(), Q_VOID, and read().

Referenced by QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead(), and ICOReader::canRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ waitForBytesWritten()

bool QIODevice::waitForBytesWritten ( int msecs)
virtual

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.

If msecs is -1, this function 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 function 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 reemitted.

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

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

Reimplemented in QAbstractSocket, QLocalSocket, and QSslSocket.

Definition at line 2104 of file qiodevice.cpp.

References Q_UNUSED.

◆ waitForReadyRead()

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 function will not time out.

Returns true if new data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).

This function 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 function to provide a blocking API for a custom device. The default implementation does nothing, and returns false.

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

Reimplemented in QAbstractSocket, QLocalSocket, and QSslSocket.

Definition at line 2072 of file qiodevice.cpp.

References Q_UNUSED.

◆ write() [1/3]

qint64 QIODevice::write ( const char * data)
Since
4.5

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

...
QIODevice::write(data, qstrlen(data));
...
size_t qstrlen(const char *str)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
See also
read(), writeData()

Definition at line 1727 of file qiodevice.cpp.

References qstrlen(), and write().

+ Here is the call graph for this function:

◆ write() [2/3]

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

Definition at line 1639 of file qiodevice.cpp.

References blockSize, CHECK_MAXLEN, CHECK_WRITABLE, d, forever, ret, seek(), QIODeviceBase::Text, write(), and writeData().

Referenced by QVncClient::QVncClient(), QWasmAudioSink::QWasmAudioSink(), QGeoFileTileCache::~QGeoFileTileCache(), QPdfDocumentPrivate::_q_copyFromSequentialSourceDevice(), QZipWriterPrivate::addEntry(), QGeoFileTileCache::addToDiskCache(), QNetworkReplyImplPrivate::appendDownstreamData(), QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer(), QSocks5PasswordAuthenticator::beginAuthenticate(), NS_IIOF_HELPERS::cbPutBytes(), QZipWriter::close(), connectToHost(), QTlsPrivate::TlsCryptographOpenSSL::continueHandshake(), dumpOutput(), QDarwinAudioSourceBuffer::flush(), QTextStreamPrivate::flushWriteBuffer(), QmlTypesCreator::generate(), mergeGradleProperties(), QPdf::ByteStream::operator<<(), QPdf::ByteStream::operator<<(), QPdf::ByteStream::operator<<(), QPdf::ByteStream::operator<<(), QDataStream::operator<<(), QDataStream::operator<<(), QDataStream::operator<<(), QDataStream::operator<<(), QDataStream::operator<<(), RCCResourceLibrary::output(), QSSGQmlUtilities::outputTextureAsset(), patchQtCore(), QHttpNetworkConnectionChannel::pipelineFlush(), printError(), dtlsbio::q_dgram_write(), qt_cbor_encoder_write_callback(), qt_empty_output_buffer(), qt_term_destination(), QAlsaAudioSource::read(), QPulseAudioSource::read(), RCCResourceLibrary::readFiles(), QFFmpeg::AudioRenderer::renderInternal(), QNetworkReplyHttpImplPrivate::replyDownloadData(), QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(), QmlTypeRegistrar::runExtract(), runRcc(), QGtk3Json::save(), QPicture::save(), QFileDialog::saveFileContent(), QHttpProtocolHandler::sendRequest(), dom::DataTransfer::toMimeDataWithFile(), QTlsPrivate::TlsCryptographSchannel::transmit(), updateFile(), updateStringsXml(), QNetworkAccessFileBackend::uploadReadyReadSlot(), QRfbRawEncoder::write(), write(), write(), QQmlPreviewFileEngine::write(), write(), QWebpHandler::write(), Jpeg2000JasperReader::write(), QTextDocumentWriter::write(), QQmlJSStreamWriter::write(), Http2::FrameWriter::write(), writeBMPInfoHeader(), QWaveDecoder::writeData(), QBluetoothSocketPrivateBluezDBus::writeData(), Http2::FrameWriter::writeDATA(), RCCFileInfo::writeDataBlob(), QQmlJSStreamWriter::writeEndObject(), QQmlJSStreamWriter::writeEnumObjectLiteralBinding(), Http2::FrameWriter::writeHEADERS(), writeIconDir(), writeIconDirEntry(), QQmlJSStreamWriter::writeLibraryImport(), QSSGQmlUtilities::writeQmlForAnimation(), QDataStream::writeRawData(), QQmlJSStreamWriter::writeStartObject(), QQuickTextDocumentPrivate::writeTo(), QPacketProtocolPrivate::writeToDevice(), writeWBMPData(), and writeWBMPHeader().

+ Here is the call graph for this function:

◆ write() [3/3]

qint64 QIODevice::write ( const QByteArray & data)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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()

Definition at line 1741 of file qiodevice.cpp.

References d, QRINGBUFFER_CHUNKSIZE, ret, and write().

+ Here is the call graph for this function:

◆ writeChannelCount()

int QIODevice::writeChannelCount ( ) const
Since
5.7

Returns the number of available write channels if the device is open; otherwise returns 0.

See also
readChannelCount()

Definition at line 614 of file qiodevice.cpp.

Referenced by QSslSocketPrivate::_q_connectedSlot(), and if().

+ Here is the caller graph for this function:

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

Implemented in qstdweb::BlobIODevice, QLocalSocket, OurSink, QAudioOutputStream, QDarwinAudioSinkDevice, QDarwinAudioSourceDevice, QnxPushIODevice, NullDevice, QBuffer, QFileDevice, QNetworkReply, QAbstractSocket, QSslSocket, AlsaOutputPrivate, AlsaInputPrivate, SLIODevicePrivate, QSoundEffectPrivate, QWaveDecoder, PulseOutputPrivate, PulseInputPrivate, InputPrivate, QWasmAudioSinkDevice, QWasmAudioSourceDevice, OutputPrivate, QFFmpeg::AudioSourceIO, GStreamerOutputPrivate, GStreamerInputPrivate, QIOPipe, QByteDeviceWrappingIoDevice, QHttpMultiPartIODevice, QLocalUnixSocket, QBluetoothSocket, and qstdweb::Uint8ArrayIODevice.

Referenced by write(), and QLocalUnixSocket::writeData().

+ Here is the caller graph for this function:

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