summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-10-31 15:25:55 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-01-24 18:48:31 +0000
commit87a176a8b39c16092d054a564d04937ff5042884 (patch)
treeae4669885aafadf7f5d47d465af5e313a7bcf029
parent86abefbf4b01deb5961c3bd47b6d637c5ea393b1 (diff)
downloadqtbase-87a176a8b39c16092d054a564d04937ff5042884.tar.gz
Restore Android-conditioning on nl_langinfo() definition
QCoreApplicationPrivate::initLocale()'s check that the selected locale is UTF-8-based was added with an initial work-around for Android, specific to NDK <= 15, which Qt 5.15 did not support. Later the Android-specific #if-ery was changed to test for Qt taking UTF-8 for granted, for a given reason having to do with QNX; and later the #if-ery for that was removed. However, we still support versions of Android that lack nl_langinfo(), so restore the Android #if-ery. It presently seems that NDK 26 (Android 8) does contain nl_langinfo(), so we should be able to drop the nl_langinfo() kludge for this and later versions. That way we'll at least use the real nl_langinfo() where we have it. In the process, fix the indentation of #if-ery. Change-Id: Ie9e83c3397955c24cea1e9a9ff6bb0187e47dda2 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 10117f78d72498e19683e69b439ca7c931532261) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 3fe706b810..e04502dcbd 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -553,12 +553,14 @@ void QCoreApplicationPrivate::initLocale()
return;
qt_locale_initialized = true;
-#ifdef Q_OS_INTEGRITY
+# ifdef Q_OS_INTEGRITY
setlocale(LC_CTYPE, "UTF-8");
-#else
- // Android's Bionic didn't get nl_langinfo until NDK 15 (Android 8.0),
- // which is too new for Qt, so we just assume it's always UTF-8.
+# else
+# if defined(Q_OS_QNX) || (defined(Q_OS_ANDROID) && __ANDROID_API__ < __ANDROID_API_O__)
+ // Android 6 still lacks nl_langinfo(), as does QNX, so we just assume it's
+ // always UTF-8 on these platforms.
auto nl_langinfo = [](int) { return "UTF-8"; };
+# endif // QNX or Android NDK < 26, "O".
const char *locale = setlocale(LC_ALL, "");
const char *codec = nl_langinfo(CODESET);
@@ -573,10 +575,10 @@ void QCoreApplicationPrivate::initLocale()
newLocale = setlocale(LC_CTYPE, newLocale);
// if locale doesn't exist, try some fallbacks
-# ifdef Q_OS_DARWIN
+# ifdef Q_OS_DARWIN
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "UTF-8");
-# endif
+# endif
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "C.UTF-8");
if (newLocale.isEmpty())
@@ -587,8 +589,8 @@ void QCoreApplicationPrivate::initLocale()
"reconfigure your locale. See the locale(1) manual for more information.",
codec, oldLocale.constData(), newLocale.constData());
}
-#endif
-#endif
+# endif // Integrity
+#endif // Unix
}