Qyoto
4.0.5
Qyoto is a C# language binding for Qt
|
The QIODevice class is the base interface class of all I/O devices in Qt. More...
Public Types | |
enum | OpenModeFlag { Append = 4, NotOpen = 0, ReadOnly = 1, ReadWrite = 3, Text = 16, Truncate = 8, Unbuffered = 32, WriteOnly = 2 } |
More... | |
Public Member Functions | |
QIODevice () | |
| |
QIODevice (QObject parent) | |
| |
override void | CreateProxy () |
virtual bool | AtEnd () |
| |
virtual long | BytesAvailable () |
| |
virtual long | BytesToWrite () |
| |
virtual bool | CanReadLine () |
| |
virtual void | Close () |
| |
new string | ErrorString () |
| |
new bool | GetChar (Pointer< sbyte > c) |
| |
new bool | IsOpen () |
| |
new bool | IsReadable () |
| |
virtual bool | IsSequential () |
| |
new bool | IsTextModeEnabled () |
| |
new bool | IsWritable () |
| |
virtual bool | Open (QIODevice.OpenModeFlag mode) |
| |
new QIODevice.OpenModeFlag | OpenMode () |
| |
new QByteArray | Peek (long maxlen) |
| |
new long | Peek (Pointer< sbyte > data, long maxlen) |
| |
virtual long | Pos () |
| |
new bool | PutChar (sbyte c) |
| |
new QByteArray | Read (long maxlen) |
| |
new long | Read (Pointer< sbyte > data, long maxlen) |
| |
new QByteArray | ReadAll () |
| |
new QByteArray | ReadLine (long maxlen=0) |
| |
new long | ReadLine (Pointer< sbyte > data, long maxlen) |
| |
virtual bool | Reset () |
| |
virtual bool | Seek (long pos) |
| |
new void | SetTextModeEnabled (bool enabled) |
| |
virtual long | Size () |
| |
new void | UngetChar (sbyte c) |
| |
virtual bool | WaitForBytesWritten (int msecs) |
| |
virtual bool | WaitForReadyRead (int msecs) |
| |
new long | Write (QByteArray data) |
| |
new long | Write (string data) |
| |
new long | Write (string data, long len) |
| |
new void | Dispose () |
Public Member Functions inherited from QtCore.QObject | |
QObject (QObject parent=null) | |
| |
new bool | BlockSignals (bool b) |
| |
new System.Collections.Generic.List < QObject > | Children () |
| |
new bool | Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
new void | DeleteLater () |
| |
new bool | Disconnect (QObject receiver, string member=null) |
| |
new bool | Disconnect (string signal=null, QObject receiver=null, string member=null) |
| |
new void | DumpObjectInfo () |
| |
new void | DumpObjectTree () |
| |
new System.Collections.Generic.List < QByteArray > | DynamicPropertyNames () |
| |
virtual bool | OnEvent (QEvent arg1) |
| |
virtual bool | EventFilter (QObject arg1, QEvent arg2) |
| |
new bool | Inherits (string classname) |
| |
new void | InstallEventFilter (QObject arg1) |
| |
new bool | IsWidgetType () |
| |
new void | KillTimer (int id) |
| |
new object | Property (string name) |
| |
new void | RemoveEventFilter (QObject arg1) |
| |
new bool | SetProperty (string name, object value) |
| |
new void | SetUserData (uint id, QObjectUserData data) |
new bool | SignalsBlocked () |
| |
new int | StartTimer (int interval) |
| |
new QObjectUserData | UserData (uint id) |
new void | Dispose () |
Public Member Functions inherited from QtCore.Qt | |
delegate QTextStream | FuncQTextStreamQTextStream (QTextStream qTextStream) |
delegate string | FuncStringQByteArray (QByteArray qByteArray) |
delegate QByteArray | FuncQByteArrayString (string @string) |
delegate void | ActionQtMsgTypeString (QtMsgType qtMsgType, string @string) |
delegate QObject | FuncQObject () |
Static Public Member Functions | |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtCore.QObject | |
static bool | Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
static bool | Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection) |
| |
static bool | Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member) |
| |
static bool | Disconnect (QObject sender, string signal, QObject receiver, string member) |
| |
static uint | RegisterUserData () |
static string | Tr (string s, string c=null) |
| |
static string | Tr (string s, string c, int n) |
| |
static string | TrUtf8 (string s, string c=null) |
| |
static string | TrUtf8 (string s, string c, int n) |
| |
Static Public Member Functions inherited from QtCore.Qt | |
static QDataStream | Write (QDataStream s, object p) |
static QDataStream | Write (QDataStream arg1, QSizeF arg2) |
static QTextStream | Write (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Write (QDataStream arg1, QPoint arg2) |
static QDataStream | Write (QDataStream arg1, QLineF arg2) |
static QDataStream | Write (QDataStream arg1, QPointF arg2) |
static QDataStream | Write (QDataStream arg1, QChar arg2) |
static QDataStream | Write (QDataStream arg1, QByteArray arg2) |
static QDataStream | Write (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Write (QDataStream arg1, QRectF arg2) |
static QDataStream | Write (QDataStream arg1, QDateTime arg2) |
static QDataStream | Write (QDataStream arg1, QUrl arg2) |
static QDataStream | Write (QDataStream arg1, QTime arg2) |
static QDataStream | Write (QDataStream arg1, QLocale arg2) |
static QDataStream | Write (QDataStream arg1, QBitArray arg2) |
static QDataStream | Write (QDataStream arg1, QUuid arg2) |
static QDataStream | Write (QDataStream arg1, QLine arg2) |
static QDataStream | Write (QDataStream arg1, QDate arg2) |
static QDataStream | Write (QDataStream @out, QRegExp regExp) |
static QDataStream | Write (QDataStream arg1, QRect arg2) |
static QDataStream | Write (QDataStream arg1, QSize arg2) |
static QDataStream | Write (QDataStream s, QVariant.Type p) |
static QDataStream | Write (QDataStream arg1, string arg2) |
static QDataStream | Write (QDataStream @out, System.Collections.Generic.List< string > list) |
static QDataStream | Read (QDataStream arg1, QChar arg2) |
static QDataStream | Read (QDataStream arg1, QLocale arg2) |
static QDataStream | Read (QDataStream arg1, QRect arg2) |
static QDataStream | Read (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Read (QDataStream arg1, QDate arg2) |
static QDataStream | Read (QDataStream arg1, QUrl arg2) |
static QDataStream | Read (QDataStream arg1, QUuid arg2) |
static QTextStream | Read (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Read (QDataStream arg1, QLineF arg2) |
static QDataStream | Read (QDataStream arg1, QRectF arg2) |
static QDataStream | Read (QDataStream arg1, QPointF arg2) |
static QDataStream | Read (QDataStream arg1, QLine arg2) |
static QDataStream | Read (QDataStream arg1, QBitArray arg2) |
static QDataStream | Read (QDataStream arg1, QSize arg2) |
static QDataStream | Read (QDataStream arg1, QDateTime arg2) |
static QDataStream | Read (QDataStream arg1, QTime arg2) |
static QDataStream | Read (QDataStream arg1, QPoint arg2) |
static QDataStream | Read (QDataStream @in, QRegExp regExp) |
static QDataStream | Read (QDataStream s, object p) |
static QDataStream | Read (QDataStream arg1, QByteArray arg2) |
static QDataStream | Read (QDataStream arg1, QSizeF arg2) |
static QDataStream | Read (QDataStream arg1, string arg2) |
static QDataStream | Read (QDataStream s, QVariant.Type p) |
static QDataStream | Read (QDataStream @in, System.Collections.Generic.List< string > list) |
static double | qAcos (double v) |
static void | qAddPostRoutine (System.Action arg1) |
static string | qAppName () |
static double | qAsin (double v) |
static double | qAtan (double v) |
static double | qAtan2 (double x, double y) |
static void | qBadAlloc () |
static int | qCeil (double v) |
static ushort | qChecksum (string s, uint len) |
static QByteArray | qCompress (QByteArray data) |
static QByteArray | qCompress (QByteArray data, int compressionLevel=-1) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1) |
static double | qCos (double v) |
static double | qExp (double v) |
static double | qFabs (double v) |
static double | qFastCos (double x) |
static double | qFastSin (double x) |
static string | qFlagLocation (string method) |
static int | qFloor (double v) |
static bool | qFuzzyCompare (double p1, double p2) |
static bool | qFuzzyCompare (float p1, float p2) |
static bool | qFuzzyIsNull (double d) |
static bool | qFuzzyIsNull (float f) |
static uint | qHash (QBitArray key) |
static uint | qHash (QChar key) |
static uint | qHash (QStringRef key) |
static uint | qHash (QUrl url) |
static uint | qHash (QPersistentModelIndex index) |
static uint | qHash (QByteArray key) |
static uint | qHash (QModelIndex index) |
static uint | qHash (uint key) |
static uint | qHash (sbyte key) |
static uint | qHash (byte key) |
static uint | qHash (short key) |
static uint | qHash (NativeLong key) |
static uint | qHash (ushort key) |
static uint | qHash (long key) |
static uint | qHash (ulong key) |
static uint | qHash (int key) |
static uint | qHash (string key) |
static uint | qHash (NativeULong key) |
static double | qInf () |
static Qt.ActionQtMsgTypeString | qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1) |
static int | qIntCast (float f) |
static int | qIntCast (double f) |
static bool | qIsFinite (double d) |
static bool | qIsFinite (float f) |
static bool | qIsInf (float f) |
static bool | qIsInf (double d) |
static bool | qIsNaN (float f) |
static bool | qIsNaN (double d) |
static bool | qIsNull (float f) |
static bool | qIsNull (double d) |
static double | qLn (double v) |
static double | qPow (double x, double y) |
static double | qQNaN () |
static void | qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function) |
static void | qRemovePostRoutine (System.Action arg1) |
static int | qRound (double d) |
static long | qRound64 (double d) |
static double | qSNaN () |
static bool | qSharedBuild () |
static double | qSin (double v) |
static double | qSqrt (double v) |
static bool | qStringComparisonHelper (QStringRef s1, string s2) |
static double | qTan (double v) |
static QByteArray | qUncompress (QByteArray data) |
static QByteArray | qUncompress (Pointer< byte > data, int nbytes) |
static string | qVersion () |
static void | Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size) |
static QByteArray | Qgetenv (string varName) |
static bool | Qputenv (string varName, QByteArray value) |
static int | Qrand () |
static void | Qsrand (uint seed) |
static int | Qstrcmp (QByteArray str1, QByteArray str2) |
static int | Qstrcmp (QByteArray str1, string str2) |
static int | Qstrcmp (string str1, QByteArray str2) |
static int | Qstrcmp (string str1, string str2) |
static Pointer< sbyte > | Qstrcpy (Pointer< sbyte > dst, string src) |
static Pointer< sbyte > | Qstrdup (string arg1) |
static int | Qstricmp (string arg1, string arg2) |
static uint | Qstrlen (string str) |
static int | Qstrncmp (string str1, string str2, uint len) |
static Pointer< sbyte > | Qstrncpy (Pointer< sbyte > dst, string src, uint len) |
static int | Qstrnicmp (string arg1, string arg2, uint len) |
static uint | Qstrnlen (string str, uint maxlen) |
static string | QtTrId (string id, int n=-1) |
Protected Member Functions | |
QIODevice (System.Type dummy) | |
new void | OnAboutToClose () |
| |
new void | OnBytesWritten (long bytes) |
| |
new void | OnReadChannelFinished () |
| |
abstract long | ReadData (Pointer< sbyte > data, long maxlen) |
| |
virtual long | ReadLineData (Pointer< sbyte > data, long maxlen) |
| |
new void | OnReadyRead () |
| |
new void | SetErrorString (string errorString) |
| |
new void | SetOpenMode (QIODevice.OpenModeFlag openMode) |
| |
abstract long | WriteData (string data, long len) |
| |
Protected Member Functions inherited from QtCore.QObject | |
QObject (System.Type dummy) | |
virtual void | OnChildEvent (QChildEvent arg1) |
| |
virtual void | ConnectNotify (string signal) |
| |
virtual void | OnCustomEvent (QEvent arg1) |
| |
new void | OnDestroyed (QObject arg1=null) |
| |
virtual void | DisconnectNotify (string signal) |
| |
new int | Receivers (string signal) |
| |
new QObject | Sender () |
| |
new int | SenderSignalIndex () |
| |
virtual void | OnTimerEvent (QTimerEvent arg1) |
| |
Properties | |
Slot | ReadyRead |
| |
Slot< System.Int64 > | BytesWritten |
| |
Slot | AboutToClose |
| |
Slot | ReadChannelFinished |
| |
static new QMetaObject | StaticMetaObject [get] |
new IQIODeviceSignals | Emit [get] |
Properties inherited from QtCore.QObject | |
virtual EventHandler < QEventArgs< QChildEvent > > | ChildEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | CustomEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | Event |
| |
virtual EventHandler < QEventArgs< QTimerEvent > > | TimerEvent |
| |
Slot< QObject > | DestroyedQObject |
Slot | Destroyed |
| |
new QObject | Parent [get, set] |
| |
virtual System.IntPtr | SmokeObject [get, set] |
new string | ObjectName [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
| |
static new QMetaObject | StaticQtMetaObject [get] |
new IQObjectSignals | Emit [get] |
Additional Inherited Members | |
Protected Attributes inherited from QtCore.QObject | |
object | Q_EMIT = null |
SmokeInvocation | interceptor |
readonly List< QEventHandler > | eventFilters = new List<QEventHandler>() |
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 can not 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.
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.
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:
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 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. Example:
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 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.
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.
|
protected |
QtCore.QIODevice.QIODevice | ( | ) |
Constructs a QIODevice object.
|
virtual |
Returns true if the current read and write position is at the end of the device (i.e. there is no more data available for reading on the device); otherwise returns false.
For some devices, atEnd() can return true even though there is more data to read. This special case only applies to devices that generate data in direct response to you calling read() (e.g., /dev or /proc files on Unix and Mac OS X, or console input / stdin on all platforms).
See also bytesAvailable(), read(), and isSequential().
Reimplemented in QtCore.QProcess, QtCore.QFile, QtNetwork.QSslSocket, QtCore.QBuffer, and QtNetwork.QAbstractSocket.
|
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 QIODevices' buffer. Example:
qint64 CustomDevice::bytesAvailable() const
{
return buffer.size() + QIODevice::bytesAvailable();
}
See also bytesToWrite(), readyRead(), and isSequential().
Reimplemented in QtCore.QProcess, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
|
virtual |
For buffered devices, this function returns the number of bytes waiting to be written. For devices with no buffer, this function returns 0.
See also bytesAvailable(), bytesWritten(), and isSequential().
Reimplemented in QtCore.QProcess, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
|
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() and readLine().
Reimplemented in QtCore.QProcess, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, QtCore.QBuffer, and QtNetwork.QAbstractSocket.
|
virtual |
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. The error string is also reset.
See also setOpenMode() and OpenMode.
Reimplemented in QtCore.QProcess, QtCore.QFile, QtNetwork.QSslSocket, QtNetwork.QNetworkReply, QtNetwork.QLocalSocket, QtCore.QBuffer, and QtNetwork.QAbstractSocket.
|
virtual |
Reimplemented from QtCore.QObject.
Reimplemented in QtCore.QTemporaryFile, QtCore.QProcess, QtNetwork.QUdpSocket, QtNetwork.QTcpSocket, QtNetwork.QSslSocket, QtNetwork.QNetworkReply, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
new void QtCore.QIODevice.Dispose | ( | ) |
new string QtCore.QIODevice.ErrorString | ( | ) |
Returns a human-readable description of the last device error that occurred.
See also setErrorString().
new bool QtCore.QIODevice.GetChar | ( | Pointer< sbyte > | 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(), and ungetChar().
new bool QtCore.QIODevice.IsOpen | ( | ) |
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() and OpenMode.
new bool QtCore.QIODevice.IsReadable | ( | ) |
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() and OpenMode.
|
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 QtCore.QProcess, QtCore.QFile, QtNetwork.QNetworkReply, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
new bool QtCore.QIODevice.IsTextModeEnabled | ( | ) |
Returns true if the Text flag is enabled; otherwise returns false.
See also setTextModeEnabled().
new bool QtCore.QIODevice.IsWritable | ( | ) |
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() and OpenMode.
|
protected |
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).
|
protected |
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.
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().
|
protected |
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().
This function was introduced in Qt 4.4.
See also atEnd() and read().
|
protected |
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().
|
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() and OpenMode.
Reimplemented in QtCore.QTemporaryFile, QtCore.QFile, and QtCore.QBuffer.
new QIODevice.OpenModeFlag QtCore.QIODevice.OpenMode | ( | ) |
Returns the mode in which the device has been opened; i.e. ReadOnly or WriteOnly.
See also setOpenMode() and OpenMode.
new QByteArray QtCore.QIODevice.Peek | ( | long | maxlen | ) |
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:
bool isExeFile(QFile *file)
{
char buf[2];
if (file->peek(buf, sizeof(buf)) == sizeof(buf))
return (buf[0] == 'M' && buf[1] == 'Z');
return false;
}
This function was introduced in Qt 4.1.
See also read().
new long QtCore.QIODevice.Peek | ( | Pointer< sbyte > | data, |
long | maxlen | ||
) |
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:
bool isExeFile(QFile *file)
{
char buf[2];
if (file->peek(buf, sizeof(buf)) == sizeof(buf))
return (buf[0] == 'M' && buf[1] == 'Z');
return false;
}
This function was introduced in Qt 4.1.
See also read().
|
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() and seek().
Reimplemented in QtCore.QFile, and QtCore.QBuffer.
new bool QtCore.QIODevice.PutChar | ( | sbyte | c | ) |
Writes the character c to the device. Returns true on success; otherwise returns false.
See also write(), getChar(), and ungetChar().
new QByteArray QtCore.QIODevice.Read | ( | long | maxlen | ) |
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(), and write().
new long QtCore.QIODevice.Read | ( | Pointer< sbyte > | data, |
long | maxlen | ||
) |
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(), and write().
new QByteArray QtCore.QIODevice.ReadAll | ( | ) |
This is an overloaded function.
Reads all available data from the device, and returns it 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.
|
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.
See also read(), readLine(), and writeData().
Implemented in QtCore.QProcess, QtCore.QFile, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, QtCore.QBuffer, and QtNetwork.QAbstractSocket.
new QByteArray QtCore.QIODevice.ReadLine | ( | long | maxlen = 0 | ) |
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 ocurred, 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:
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 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(), and write().
new long QtCore.QIODevice.ReadLine | ( | Pointer< sbyte > | data, |
long | 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. If a line could not be read but no error ocurred, 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:
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 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(), and write().
|
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 QtCore.QFile, and QtNetwork.QAbstractSocket.
|
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().
|
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 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() and isSequential().
Reimplemented in QtCore.QFile, and QtCore.QBuffer.
|
protected |
Sets the human readable description of the last device error that occurred to str.
See also errorString().
|
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() and OpenMode.
new void QtCore.QIODevice.SetTextModeEnabled | ( | bool | enabled | ) |
If enabled is true, this function 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 function.
See also isTextModeEnabled(), open(), and setOpenMode().
|
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() and pos().
Reimplemented in QtCore.QFile, and QtCore.QBuffer.
|
static |
|
static |
|
static |
|
static |
new void QtCore.QIODevice.UngetChar | ( | sbyte | 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.
|
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 QtCore.QProcess, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
|
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 QtCore.QProcess, QtNetwork.QSslSocket, QtNetwork.QLocalSocket, and QtNetwork.QAbstractSocket.
new long QtCore.QIODevice.Write | ( | QByteArray | data | ) |
This is an overloaded function.
Writes the content of byteArray to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.
See also read() and writeData().
new long QtCore.QIODevice.Write | ( | string | data | ) |
This is an overloaded function.
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));
...
This function was introduced in Qt 4.5.
See also read() and writeData().
new long QtCore.QIODevice.Write | ( | string | data, |
long | len | ||
) |
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() and writeData().
|
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() and write().
Implemented in QtCore.QProcess, QtCore.QFile, QtNetwork.QSslSocket, QtNetwork.QNetworkReply, QtNetwork.QLocalSocket, QtCore.QBuffer, and QtNetwork.QAbstractSocket.
|
addremove |
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).
|
addremove |
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.
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().
|
getprotected |
|
addremove |
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().
This function was introduced in Qt 4.4.
See also atEnd() and read().
|
addremove |
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().
|
staticget |