From 618fea9e2006475bf849da1c1837e0d788f30a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 15 Nov 2023 11:56:22 +0100 Subject: [PATCH] qt: On Windows, use UTF-8 when logging the error text * lang/qt/src/debug.cpp (operator<<): On Windows, interpret the error text as UTF-8 instead of local 8-bit encoding. -- GnuPG-bug-id: 5960 --- lang/qt/src/debug.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lang/qt/src/debug.cpp b/lang/qt/src/debug.cpp index b563ac0c..2f6d200b 100644 --- a/lang/qt/src/debug.cpp +++ b/lang/qt/src/debug.cpp @@ -42,8 +42,14 @@ QDebug operator<<(QDebug debug, const GpgME::Error &err) { +#ifdef Q_OS_WIN + // On Windows, we tell libgpg-error to return (translated) error messages as UTF-8 + const auto errAsString = QString::fromUtf8(err.asString()); +#else + const auto errAsString = QString::fromLocal8Bit(err.asString()); +#endif const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << err.asString() << " (code: " << err.code() << ", source: " << err.source() << ")"; + debug.nospace() << errAsString << " (code: " << err.code() << ", source: " << err.source() << ")"; debug.setAutoInsertSpaces(oldSetting); return debug.maybeSpace(); }