Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
4.6.2
-
None
Description
Reading text file trough QFile\QTextStream. Windows 7. File text encoding: system (CP-1251). Line ending 0D0A
Some lines in file starts with one zero byte. Seems multiline char* strings (with endl at end) wroten to file as is including \0 terminator.
QFile file; QTextStream str; qulonglong pos; QString line; ... file.close(); file.setFileName(path); file.open(QFile::ReadOnly|QIODevice::Text); str.setDevice(&file); str.read(5); // to recognize file encoding (bug too?) str.seek(pos); ... line = str.readLine(); \\ok while no zero chars in file ... // if zero char meets in this line line = str.readLine(); \\ bug: skips one char just after zero. But zero and others reads fine ... // if zero char meets in some previous line line = str.readLine(); \\ bug: may skip some first simbols if line starts with 'D' ...
to walkaround I use char by char reading with go one char back every \0 meeting
forever { QChar c; str >> c; if(c.isNull()) { str.seek(str.pos()-1); continue;// comment it out to get same as readLine result } else if(c == QChar('\n')) break; ret+=c; }