From 8db031cb0f2159d11463d92c56ccdaf858a0e792 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 12 Jul 2021 10:46:14 +0200 Subject: [PATCH] Change QCollator's default locale to QLocale().collation() This replaces QLocale::system().collation(), which left client code with no way to change this default. Since QLocale's default is the system locale initially, the old behavior is retained until the first call to QLocale;:setDefault(). Addition of a separate collation locale in 5.14 changed from using the default locale to using the system's collation locale; the present change restores the ability to override this. [ChangeLog][QtCore][QCollator] The default locale used by QCollator is now the collation locale of the default QLocale. This restores the ability (lost at 5.14) to control the locale used by QString::localeAwareCompare(), while retaining the use of a collation locale when the default is the system locale. Task-number: QTBUG-95050 Change-Id: I232772bb8f23fffd74573174de70ef2deae372a9 Reviewed-by: Volker Hilsheimer (cherry picked from commit 973ca1fac680d8c593645058fae3fe7c84a7fa16) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qcollator.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qcollator.cpp b/src/corelib/text/qcollator.cpp index b6c9f7680ab..425bfc82ff8 100644 --- a/src/corelib/text/qcollator.cpp +++ b/src/corelib/text/qcollator.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2013 Aleix Pol Gonzalez ** Contact: https://www.qt.io/licensing/ ** @@ -77,12 +77,16 @@ QT_BEGIN_NAMESPACE /*! \since 5.13 - Constructs a QCollator using the system's default collation locale. + Constructs a QCollator using the default locale's collation locale. - \sa setLocale(), QLocale::collation() + The system locale, when used as default locale, may have a collation locale + other than itself (e.g. on Unix, if LC_COLLATE is set differently to LANG in + the environment). All other locales are their own collation locales. + + \sa setLocale(), QLocale::collation(), QLocale::setDefault() */ QCollator::QCollator() - : d(new QCollatorPrivate(QLocale::system().collation())) + : d(new QCollatorPrivate(QLocale().collation())) { d->init(); }