Lesson 33rd text flow and data flow

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.