Details
-
Bug
-
Resolution: Done
-
P2: Important
-
6.3.0
-
None
-
-
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?