Remove a couple of QTextStream usages
Don't use QTextStream to write a QString to a file in UTF-8. This can be done more easily, by directly converting the QString to utf-8 and calling write on the io device. Change-Id: I4b617b342ab339affb396ed49c5a920985d1ddfd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
parent
a308df82ae
commit
5acc3dd242
@ -122,9 +122,9 @@ void MainWindow::save()
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out.setCodec(codecName.constData());
|
||||
out << textEdit->toPlainText();
|
||||
QTextCodec *codec = QTextCodec::codecForName(codecName.constData());
|
||||
QByteArray text = codec->fromUnicode(textEdit->toPlainText());
|
||||
file.write(text);
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
|
@ -154,10 +154,7 @@ bool MainWindow::writeXml(const QString &fileName)
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
QTextStream textStream(&file);
|
||||
textStream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
textStream << domDocument->toString(1).toUtf8();
|
||||
file.write(domDocument->toString(1).toUtf8());
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
@ -159,10 +159,7 @@ bool MainWindow::writeXml(const QString &fileName)
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
QTextStream textStream(&file);
|
||||
textStream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
textStream << domDocument->toString(1).toUtf8();
|
||||
file.write(domDocument->toString(1).toUtf8());
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
@ -202,10 +202,7 @@ bool MainWindow::writeXml(const QString &fileName)
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
QTextStream textStream(&file);
|
||||
textStream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
textStream << domDocument->toString(1).toUtf8();
|
||||
file.write(domDocument->toString(1).toUtf8());
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
@ -286,11 +286,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
|
||||
qWarning("QTextDocumentWriter::write: the device cannot be opened for writing");
|
||||
return false;
|
||||
}
|
||||
QTextStream ts(d->device);
|
||||
#if QT_CONFIG(textcodec)
|
||||
ts.setCodec("utf-8");
|
||||
#endif
|
||||
ts << document->toPlainText();
|
||||
d->device->write(document->toPlainText().toUtf8());
|
||||
d->device->close();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user