I work on project that involved writing binary data, I use QString for storing line and then save it on hard by Qfile
data.append(QChar(10));
and I set encoding to “ISO-8859-1”, anyway when the data equal to 10 I as showed above, the saved data is 0x0d,0x0a I find the problem source ,10=’\n’ and Qt change it to ‘\n\r’ so it happened.
How can I fix it?
I found the reason, because the QFile object that I had created is in Text mode so when QFile want to write file it changes /n to /r/n the code below is the previous code that have problem in binary because of existence of
QIODevice::Textfor binary mode simply we can omite
QIODevice::Textso the second line change toat first I think this is the Qt’s bug, and try to use ofstream to write file, the same thing happened with ofstream, and finally writing binary code with ofstream is showed below
the point is
std::ios_base::binary