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

QTextStream::setCodec() won't change codec after first execution of QTextStream::flush()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.3.2
    • Core: I/O
    • None
    • Windows 7 64bit, Visual Studio 2010 32it, Qt 5.3.2 32bit

    Description

      In a project Im using QTextStream to write several language translations into a single file using different code pages (Windows-1250 for English and Polish and Windows-1251 for Russian).
      Example of generated output file (using QT 4.8.4): http://pastebin.com/rgd7Pfj7
      I used to change the codec "on the fly" using QT 4.8 this way:

      QFile f;
      QTextStream ts(&f);
      ts.setCodec("Windows-1250");
      ts << englishTranslationBlock();
      ts << polishTranslationBlock();
      ts.flush();
      ts.setCodec("Windows-1251");
      ts << russianTranslationBlock();
      ts.flush();
      f.close();

      so the output data was coded different code pages each block of text.

      In QT 5.3.2 Iv noticed this is not possible anymore. Whole file is coded using code page defined by the first execution of QTextStream::setCodec().
      Iv check the QT5 source and find out that when QTextStream::flush() is executed QIcuCodec::getConverter() is called and converter is initialized: line 5 here - http://pastebin.com/2dEcCyET . When QTextStream::setCodec() is executed for the second time, converter is not initialized with new settings after the QTextStream::flush() and the code page will not be changed.

      Im not sure if I explained correctly but the problem is that it is not possible to change the codec "on the fly" with setCodec(). At the moment to bypass this problem Im creating new QTextStream object every time I want to change the code page:

      QFile f;
      QTextStream* ts = new QTextStream(&f);
      ts->setCodec("Windows-1250");
      ts << englishTranslationBlock();
      ts << polishTranslationBlock();
      ts->flush();
      delete ts;
      ts = new QTextStream(&f);
      ts->setCodec("Windows-1251");
      ts << russianTranslationBlock();
      ts->flush();
      f.close();

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            killdaclick Maciej Andrzejewski
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes