[QT learning] sketch qiodevice: Text Parameter

Source: Internet
Author: User

Tag: QT binary C ++

Sketch qiodevice: Text parameter:
QIODevice::Text
0x0010
After this option is used: For the read: end-of-line terminator, it is translated as '\ n'; For the write: the end-of-line terminator is translated into characters corresponding to the local encoding method. For example, in Win32, It is '\ r \ n'
When the qiodevice: Text option is used to read and write binary files, the read and write data inconsistency is caused by the translation. The test example is as follows:
 if (!fileRead.open(QIODevice::ReadOnly | QIODevice::Text)) {        qDebug() << "file open error!\r\n";        //return (0); } if (!fileWrite.open(QIODevice::WriteOnly | QIODevice::Text)) {        qDebug() << "file not exist!\r\n"; }

Yes,0x0d in the original binary file is regarded as the Terminator, which is ignored during writing. 0x0a is translated as 0x0d 0x0a (\ r \ n) in Win32).
After the qiodevice: Text option is removed, the read and write data is consistent (the test data volume is 8 kb in multiple bytes ):
if (!fileRead.open(QIODevice::ReadOnly)) {        qDebug() << "file open error!\r\n";        //return (0);    }    if (!fileWrite.open(QIODevice::WriteOnly)) {        qDebug() << "file not exist!\r\n";    }

[QT learning] sketch qiodevice: Text Parameter

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.