Qt QIODevice class is all I / O devices based interface class provides an abstract interface such as a QFile, QBuffer QTcpSocket other support and the read / write device data block. QIODevice class is abstract and can not be instantiated, it defines an interface is generally used to provide device-independent I / O functions.
First, the file open mode
Access a device before, you need to use the open () function to open the device, and must specify the correct open mode. All QIODevice open mode is defined by QIODevice :: OPenMode enumeration, its value as tabulated below, some of which may be used in the value of the bit or the symbol "| 'or be used simultaneously. After opening the device can use the write () or putChar () to write to people, use read (), readLine () or readAll () to read, using the last close () Turn off the device.
Enumeration values | description |
---|---|
QIODevice :: NotOpen | Is not open |
QIODevice::ReadOnly | Read-only |
QIODevice::WriteOnly | Open for writing only |
QIODevice::ReadWrite | Open reading and writing |
QIODevice::Append | Additional way to open the new additions will be appended to the end of the file |
QIODevice::Truncate | To rewrite the way open, when writing new data will set the cursor at the beginning of the file |
QIODevice::Text | When reading, converting into a line terminator \ n-; during writing, the cost to the end breaks to line format, for example, \ r \ n on Win32 |
QIODevice::Unbuffered | Ignore Cache |
Second, class inheritance diagram QIODevice
QIODevice will differentiate between two types of devices: random and sequential access storage devices. To determine the type of device (isSequentiaU may be used in the program) function. )
- A random access device supports seek () function to locate to an arbitrary position. The current position in the file can use the pos () function to obtain. Such devices have QFile, QBuffer and so on.
- Sequential storage device does not support the positioning to an arbitrary position, the data must be read once. POS () and size () function and the like can not be used in the operation sequence of the device. Such equipment QTcpSocket, QUdpSocket QProcess and the like.