1. file types in Qt
(1) Text file: The contents of the file are readable text characters
(2) Data file: The contents of the file are direct binary data
2. QFile class
(1) Directly support the reading and writing of text files and data files
①qint64 Read (char* data, Qint64 maxSize);
②qbytearray Read (Qint64 maxSize);
③qint64 Write (const char* data, Qint64 maxSize);
④qint64 Write (const qbytearray& byteArray);
(2) Cons: data types need to be converted
"Programming Experiment" uses Qfile to read and write directly
3. text flow and data flow
(1) QT provides helper classes to simplify the reading and writing of text files/data files
①qtextstream: All written data is converted to a readable file
②qdatastream: The written data is converted to binary data according to the type
(2) How to use IO Device helper class
//1. Create a Qfile file object (for example: file)//2. Open a file using the Files object//3. Writing data to a fileQxxxstream out(&file); out<< QString ("Santaclaus"); out<< QString ("Result:") <<3.14;//4. Read the data from the fileQxxxstreaminch(&file);inch>> DT;//DT shall be declared as qstring type;inch>> result;//result shall be declared as qstring;inch>> value;//value is declared as double;
"Programming experiments" read and write using File helper classes
(3) version information of the data stream file
① different QT versions of the data stream file format may be different when the data flow file needs to pass data between different versions of the QT program , you need to consider the version issue
② Correlation function
void setversion (int v); // set read/write version number
int version () const // Get read-write version number
4. Summary
(1) file auxiliary classes in QT for easy read and write operation
(2) Qtextstream for fast reading and writing of text data
(3) Qdatastream for fast reading and writing of binary data
(4)qdatastream file format associated with QT version
(5) When transferring data format files between programs, you need to consider the version issue
Lesson 33rd text flow and data flow