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