Qt file reading
1 and Qt, as general development libraries, provide cross-platform file manipulation capabilities. File manipulation is an indispensable part of the application.

2. QFileDevice class has been added in Qt 5. The classes involved in the journey and their uses are briefly described as follows:

Qfile: access local files or embedded resources;

Create and access temporary files of the local file system;

Q buffer: read and write q bytearray.

Qprocess: running external programs to handle inter-process communication;

Qtcpsocket: TCP protocol network data transmission;

Qudpsocket: transmitting UDP messages;

Qsslsocket: use SSL/TLS to transmit data;

Qfiledevice: A newly added class that provides a general implementation of file operations.

3. Among them, QProcess, QTcpSocket, QUdpSoctet and QSslSocket are sequential access devices. The so-called "sequential access" means that their data can only be accessed once: from beginning to end, from the first byte to the last byte, and they can't go back and read the last byte; QFile, QTemporaryFile and QBuffer are random access devices that can access any location any time. You can also use the QIODevice::seek () function to reposition the file access location pointer.

4.QFile mainly provides file-related operations such as opening, closing and refreshing files. We can use the QDataStream or QTextStream class to read and write files, and we can also use the functions such as read (), readLine (), readAll () and write () provided by QIODevice. It is worth noting that information about the file itself, such as the file name and the name of the directory where the file is located, is obtained through QFileInfo, not by analyzing the file path string itself.

5. For example, when opening a file, you need parameters to specify the mode of opening the file:

Constant value description

QIODevice::NotOpen 0x0000 device is not turned on.

Qiodevice:: Readonly 0x0001The device is turned on for reading.

QIODevice::WriteOnly 0x0002 This device is turned on for writing.

Qio device:: read write read only | write only device is turned on and can be read and written.

QIODevice::Append 0x0004 The device is turned on in Append mode, so all data is written to the end of the file.

QIODevice::Truncate 0x0008 If possible, the device is truncated before opening. All the early contents of the device will be lost.

When qiode device::Text 0x 00 10 is read, the line terminator is translated as' \n'. When writing, the line terminator is converted to local encoding, such as "\r\n" of Win32. Any buffer in the QIODevice::Unbuffered 0x0020 device is bypassed.