QLocale: try to survive being created during application shut down

QLocale is very often accessed during global static destructors, so
let's try and survive if the default has already been destroyed. In that
case, we shall fall back to the C locale.

I've placed the call to systemData(), which updates the system locale,
before the initialization of defaultLocalePrivate, as the initialization
of the latter depends on the former.

Task-number: QTBUG-133206
Pick-to: 6.9 6.8
Change-Id: I48e29b45f9be4514336cfffdf5affa5631a956a3
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Albert Astals Cid <aacid@kde.org>
This commit is contained in:
Thiago Macieira 2025-01-24 10:43:38 -08:00
parent 343dab0dc3
commit e0a1f49156

View File

@ -1211,10 +1211,13 @@ QLocale::QLocale(QStringView name)
*/
QLocale::QLocale()
: d(*defaultLocalePrivate)
: d(c_private())
{
// Make sure system data is up to date:
systemData();
if (!defaultLocalePrivate.isDestroyed()) {
// Make sure system data is up to date:
systemData();
d = *defaultLocalePrivate;
}
}
/*!