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

I doubt if QTextStream setAutoDetectUnicode doesn't work

    XMLWordPrintable

Details

    • Windows
    • c76f7cbbcb (qt/qtbase/dev) c76f7cbbcb (qt/tqtc-qtbase/dev) acaa3c6a33 (qt/qtbase/6.4) 17df321f1d (qt/qtbase/6.4.0) b607ea4ab5 (qt/tqtc-qtbase/6.2)

    Description

      #include "mainwindow.h"
      #include "qtextedit.h"
      #include "qtextstream.h"
      #include "qfile.h"
      #include "qstringconverter.h"
      #include "qiodevice.h"
      #include "qdebug.h"
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
      {
      
          textedit = new QTextEdit;
          setCentralWidget(textedit);
      
      
          QFile in("memo.txt");
      
          if (in.open(QFile::WriteOnly)){
              QTextStream instream(&in);
              instream.setEncoding(QStringConverter::Utf16);
              instream.setGenerateByteOrderMark(true);
              instream << "textedit->toPlainText()";
              in.close();
          }
      
      
          QFile out("memo.txt");
      
          if (out.open(QFile::ReadOnly)){
              QTextStream outstream(&out);
              outstream.setAutoDetectUnicode(true);
              bool a = outstream.generateByteOrderMark();
              QStringConverter::Encoding c = outstream.encoding();
      
              QString t = outstream.readAll();
              textedit->setPlainText(t);
              qDebug() << c << a;
              out.close();
          }
      }
      
      MainWindow::~MainWindow()
      {
      }
      

      out.encoding always returns 0.
      0 is Utf-8.
      setGenerateByteOrderMark is also not reflected.

      Naturally, it has no problem if I save these imformation to file together.
      But this loses compatibility with windows.
      Since windows won't be able to read them.
      If I don't do it, windows automatically read them.
      Should I get either way?
      Or what am I missing?
      Doesn't setAutoDetectUnicode mean to detect which encoding this file set?

      Attachments

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

        Activity

          People

            manordheim MÃ¥rten Nordheim
            nori Harunori Fujimoto
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes