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