From c773fabc06f47678d51363f94709653752460974 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 11 Dec 2018 10:24:54 +0100 Subject: [PATCH] Core: Fix using system codec Qt5 doesn't return a valid codec when looking up the "System" codec, but will return such a codec when asking for the codec for locale and no matching codec is available. So check whether this system codec was saved to the settings. Task-number: QTCREATORBUG-21622 Change-Id: I4dc3ab47a3a54f7e4ad4e00004c2622b26182db3 Reviewed-by: Eike Ziller --- .../coreplugin/editormanager/editormanager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 5c8f39747d4..5c91901eab5 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -3040,9 +3040,16 @@ void EditorManager::hideEditorStatusBar(const QString &id) QTextCodec *EditorManager::defaultTextCodec() { QSettings *settings = ICore::settings(); - if (QTextCodec *candidate = QTextCodec::codecForName( - settings->value(Constants::SETTINGS_DEFAULTTEXTENCODING).toByteArray())) + const QByteArray codecName = + settings->value(Constants::SETTINGS_DEFAULTTEXTENCODING).toByteArray(); + if (QTextCodec *candidate = QTextCodec::codecForName(codecName)) return candidate; + // Qt5 doesn't return a valid codec when looking up the "System" codec, but will return + // such a codec when asking for the codec for locale and no matching codec is available. + // So check whether such a codec was saved to the settings. + QTextCodec *localeCodec = QTextCodec::codecForLocale(); + if (codecName == localeCodec->name()) + return localeCodec; if (QTextCodec *defaultUTF8 = QTextCodec::codecForName("UTF-8")) return defaultUTF8; return QTextCodec::codecForLocale();