Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8743

QTextStream\QFile and zero bytes in file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.2
    • GUI: Text handling
    • 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;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            setosha Anton Sergunov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes