From b7fda954777d6ce3788a6c76e9c2dfad7bf22da0 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 7 Sep 2020 12:28:32 +0200 Subject: [PATCH] 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 --- src/plugins/coreplugin/fileutils.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/coreplugin/fileutils.cpp b/src/plugins/coreplugin/fileutils.cpp index 70effcee8f9..1bc9e16608f 100644 --- a/src/plugins/coreplugin/fileutils.cpp +++ b/src/plugins/coreplugin/fileutils.cpp @@ -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