diff --git a/src/cli/Export.cpp b/src/cli/Export.cpp index e856f5332..2f2ee65e5 100644 --- a/src/cli/Export.cpp +++ b/src/cli/Export.cpp @@ -51,7 +51,7 @@ int Export::executeWithDatabase(QSharedPointer database, QSharedPointe errorTextStream << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << endl; return EXIT_FAILURE; } - outputTextStream << xmlData.constData() << endl; + outputTextStream.write(xmlData.constData()); } else if (format.startsWith(QStringLiteral("csv"), Qt::CaseInsensitive)) { CsvExporter csvExporter; outputTextStream << csvExporter.exportDatabase(database); diff --git a/src/cli/TextStream.cpp b/src/cli/TextStream.cpp index 938fd6292..5757f90e9 100644 --- a/src/cli/TextStream.cpp +++ b/src/cli/TextStream.cpp @@ -58,6 +58,15 @@ TextStream::TextStream(const QByteArray& array, QIODevice::OpenMode openMode) detectCodec(); } +void TextStream::write(const char* str) +{ + // Workaround for an issue with QTextStream. Its operator<<(const char *string) will encode the + // string with a non-UTF-8 encoding. We work around this by wrapping the input string into + // a QString, thus enforcing UTF-8. More info: + // https://code.qt.io/cgit/qt/qtbase.git/commit?id=cec8cdba4d1b856e17c8743ba8803349d42dc701 + *this << QString(str); +} + void TextStream::detectCodec() { QString codecName = "UTF-8"; diff --git a/src/cli/TextStream.h b/src/cli/TextStream.h index 2dc116352..0091ec108 100644 --- a/src/cli/TextStream.h +++ b/src/cli/TextStream.h @@ -43,6 +43,8 @@ public: explicit TextStream(QByteArray* array, QIODevice::OpenMode openMode = QIODevice::ReadWrite); explicit TextStream(const QByteArray& array, QIODevice::OpenMode openMode = QIODevice::ReadOnly); + void write(const char* str); + private: void detectCodec(); };