Core/fileutils: Do not use QTextStream::setCodec

Gone in Qt6. Write into a string buffer and bulk convert and write that
into the file with QTextCodec.

Task-number: QTCREATORBUG-24098
Change-Id: I266e90e166a22c8b34b2963458af1cc4f5d2df82
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2020-09-07 12:28:32 +02:00
parent 8d09191d2d
commit b7fda95477

View File

@@ -327,11 +327,10 @@ bool FileUtils::updateHeaderFileGuardAfterRename(const QString &headerPath,
headerFileTextFormat.lineTerminationMode
== Utils::TextFileFormat::LFLineTerminator
? QStringLiteral("\n") : QStringLiteral("\r\n");
QTextStream outStream(&tmpHeader);
if (headerFileTextFormat.codec == nullptr)
outStream.setCodec("UTF-8");
else
outStream.setCodec(headerFileTextFormat.codec->name());
// write into temporary string,
// after that write with codec into file (QTextStream::setCodec is gone in Qt 6)
QString outString;
QTextStream outStream(&outString);
int lineCounter = 0;
while (!inStream.atEnd()) {
inStream.readLineInto(&line);
@@ -347,6 +346,10 @@ bool FileUtils::updateHeaderFileGuardAfterRename(const QString &headerPath,
}
lineCounter++;
}
const QTextCodec *textCodec = (headerFileTextFormat.codec == nullptr)
? QTextCodec::codecForName("UTF-8")
: headerFileTextFormat.codec;
tmpHeader.write(textCodec->fromUnicode(outString));
tmpHeader.close();
} else {
// if opening the temp file failed report error