From 65f8f50b107a446eee6cb1d00ab401fed8bb74a9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 31 Oct 2022 15:25:55 +0100 Subject: [PATCH] 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 Reviewed-by: Qt CI Bot (cherry picked from commit 10117f78d72498e19683e69b439ca7c931532261) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qcoreapplication.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index d9a42413e4d..0c4828b0f32 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -590,12 +590,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); @@ -610,10 +612,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()) @@ -624,8 +626,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 }