drop the feature to change the default locale

changing the default locale can have various bad effects (such as failure
to convert localized integers stored in QString) which is why there was a
warning about it. even tho UNIX has the concept of changing the locale
settings (via setlocale()) I am not willing to support such feature
because QWidget, QValidtor, etc. have their own locale feature that can
be changed at any time

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-16 20:30:31 +02:00
parent 5070e961d0
commit 3e2706dd71
16 changed files with 48 additions and 240 deletions

View file

@ -981,15 +981,7 @@ QByteArray qt_locale_codec()
return localecodec; return localecodec;
} }
// Get the first non-empty value from $LC_ALL, $LC_CTYPE, and $LANG const QByteArray lang = qGetLang();
// environment variables.
QByteArray lang = qgetenv("LC_ALL");
if (lang.isEmpty()) {
lang = qgetenv("LC_CTYPE");
}
if (lang.isEmpty()) {
lang = qgetenv("LANG");
}
const int indexOfDot = lang.indexOf('.'); const int indexOfDot = lang.indexOf('.');
if (indexOfDot != -1) { if (indexOfDot != -1) {

View file

@ -812,9 +812,7 @@ public:
TextDate, // default Qt TextDate, // default Qt
ISODate, // ISO 8601 ISODate, // ISO 8601
SystemLocaleShortDate, SystemLocaleShortDate,
SystemLocaleLongDate, SystemLocaleLongDate
DefaultLocaleShortDate,
DefaultLocaleLongDate
}; };
enum TimeSpec { enum TimeSpec {

View file

@ -445,21 +445,9 @@
\value SystemLocaleLongDate The \l{QLocale::LongFormat}{long format} used \value SystemLocaleLongDate The \l{QLocale::LongFormat}{long format} used
by the \l{QLocale::system()}{operating system}. by the \l{QLocale::system()}{operating system}.
\value DefaultLocaleShortDate The \l{QLocale::ShortFormat}{short format} specified
by the \l{QLocale::setDefault()}{application's locale}.
\value DefaultLocaleLongDate The \l{QLocale::LongFormat}{long format} used
by the \l{QLocale::setDefault()}{application's locale}.
\value SystemLocaleDate \e{This enum value is deprecated.} Use Qt::SystemLocaleShortDate \value SystemLocaleDate \e{This enum value is deprecated.} Use Qt::SystemLocaleShortDate
instead (or Qt::SystemLocaleLongDate if you want long dates). instead (or Qt::SystemLocaleLongDate if you want long dates).
\value LocaleDate \e{This enum value is deprecated.} Use Qt::DefaultLocaleShortDate
instead (or Qt::DefaultLocaleLongDate if you want long dates).
\value LocalDate \e{This enum value is deprecated.} Use Qt::SystemLocaleShortDate
instead (or Qt::SystemLocaleLongDate if you want long dates).
\note For \c ISODate formats, each \c Y, \c M and \c D represents a single digit \note For \c ISODate formats, each \c Y, \c M and \c D represents a single digit
of the year, month and day used to specify the date. Each \c H, \c M and \c S of the year, month and day used to specify the date. Each \c H, \c M and \c S
represents a single digit of the hour, minute and second used to specify the time. represents a single digit of the hour, minute and second used to specify the time.

View file

@ -123,6 +123,20 @@ static inline QStringList qGetEnvList(const char* const name)
return result; return result;
} }
// Get the first non-empty value from $LC_ALL, $LC_CTYPE and $LANG environment
// variables.
static inline QByteArray qGetLang()
{
QByteArray result = qgetenv("LC_ALL");
if (result.isEmpty()) {
result = qgetenv("LC_CTYPE");
}
if (result.isEmpty()) {
result = qgetenv("LANG");
}
return result;
}
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QCORECOMMON_P_H #endif // QCORECOMMON_P_H

View file

@ -628,14 +628,6 @@ QString QDate::longDayName(int weekday, MonthNameType type)
QLocale::system().toString(date, QLocale::ShortFormat) or QLocale::system().toString(date, QLocale::ShortFormat) or
QLocale::system().toString(date, QLocale::LongFormat). QLocale::system().toString(date, QLocale::LongFormat).
If the \a format is Qt::DefaultLocaleShortDate or
Qt::DefaultLocaleLongDate, the string format depends on the
default application locale. This is the locale set with
QLocale::setDefault(), or the system locale if no default locale
has been set. Identical to calling QLocale().toString(date,
QLocale::ShortFormat) or QLocale().toString(date,
QLocale::LongFormat).
If the date is invalid, an empty string will be returned. If the date is invalid, an empty string will be returned.
\warning The Qt::ISODate format is only valid for years in the \warning The Qt::ISODate format is only valid for years in the
@ -655,10 +647,6 @@ QString QDate::toString(Qt::DateFormat f) const
case Qt::SystemLocaleLongDate: case Qt::SystemLocaleLongDate:
return QLocale::system().toString(*this, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat return QLocale::system().toString(*this, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat); : QLocale::ShortFormat);
case Qt::DefaultLocaleShortDate:
case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat);
#ifndef QT_NO_TEXTDATE #ifndef QT_NO_TEXTDATE
case Qt::TextDate: { case Qt::TextDate: {
return QString::fromLatin1("%0 %1 %2 %3") return QString::fromLatin1("%0 %1 %2 %3")
@ -1019,11 +1007,6 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f)
return QLocale::system().toDate(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat return QLocale::system().toDate(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat); : QLocale::ShortFormat);
case Qt::DefaultLocaleShortDate:
case Qt::DefaultLocaleLongDate:
return QLocale().toDate(s, f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat);
#ifndef QT_NO_TEXTDATE #ifndef QT_NO_TEXTDATE
case Qt::TextDate: { case Qt::TextDate: {
QStringList parts = s.split(QLatin1Char(' '), QString::SkipEmptyParts); QStringList parts = s.split(QLatin1Char(' '), QString::SkipEmptyParts);
@ -1395,14 +1378,6 @@ int QTime::msec() const
QLocale::system().toString(time, QLocale::ShortFormat) or QLocale::system().toString(time, QLocale::ShortFormat) or
QLocale::system().toString(time, QLocale::LongFormat). QLocale::system().toString(time, QLocale::LongFormat).
If the \a format is Qt::DefaultLocaleShortDate or
Qt::DefaultLocaleLongDate, the string format depends on the
default application locale. This is the locale set with
QLocale::setDefault(), or the system locale if no default locale
has been set. Identical to calling QLocale().toString(time,
QLocale::ShortFormat) or QLocale().toString(time,
QLocale::LongFormat).
If the time is invalid, an empty string will be returned. If the time is invalid, an empty string will be returned.
*/ */
@ -1417,11 +1392,6 @@ QString QTime::toString(Qt::DateFormat format) const
return QLocale::system().toString(*this, format == Qt::SystemLocaleLongDate ? QLocale::LongFormat return QLocale::system().toString(*this, format == Qt::SystemLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat); : QLocale::ShortFormat);
} }
case Qt::DefaultLocaleShortDate:
case Qt::DefaultLocaleLongDate: {
return QLocale().toString(*this, format == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat);
}
case Qt::ISODate: case Qt::ISODate:
case Qt::TextDate: { case Qt::TextDate: {
QSTACKARRAY(char, snprintfbuf, 9); QSTACKARRAY(char, snprintfbuf, 9);
@ -1656,10 +1626,6 @@ QTime QTime::fromString(const QString& s, Qt::DateFormat f)
return QLocale::system().toTime(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat return QLocale::system().toTime(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat); : QLocale::ShortFormat);
case Qt::DefaultLocaleShortDate:
case Qt::DefaultLocaleLongDate:
return QLocale().toTime(s, f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat);
case Qt::ISODate: case Qt::ISODate:
case Qt::TextDate: { case Qt::TextDate: {
bool ok = true; bool ok = true;
@ -2230,14 +2196,6 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC)
QLocale::system().toString(datetime, QLocale::ShortFormat) or QLocale::system().toString(datetime, QLocale::ShortFormat) or
QLocale::system().toString(datetime, QLocale::LongFormat). QLocale::system().toString(datetime, QLocale::LongFormat).
If the \a format is Qt::DefaultLocaleShortDate or
Qt::DefaultLocaleLongDate, the string format depends on the
default application locale. This is the locale set with
QLocale::setDefault(), or the system locale if no default locale
has been set. Identical to calling QLocale().toString(datetime,
QLocale::ShortFormat) or QLocale().toString(datetime,
QLocale::LongFormat).
If the datetime is invalid, an empty string will be returned. If the datetime is invalid, an empty string will be returned.
\warning The Qt::ISODate format is only valid for years in the \warning The Qt::ISODate format is only valid for years in the
@ -2941,10 +2899,6 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
return QLocale::system().toDateTime(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat return QLocale::system().toDateTime(s, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat); : QLocale::ShortFormat);
case Qt::DefaultLocaleShortDate:
case Qt::DefaultLocaleLongDate:
return QLocale().toDateTime(s, f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
: QLocale::ShortFormat);
#if !defined(QT_NO_TEXTDATE) #if !defined(QT_NO_TEXTDATE)
case Qt::TextDate: { case Qt::TextDate: {
QStringList parts = s.split(QLatin1Char(' '), QString::SkipEmptyParts); QStringList parts = s.split(QLatin1Char(' '), QString::SkipEmptyParts);

View file

@ -156,14 +156,7 @@ static const QLocalePrivate *findLocale(const QByteArray &name)
static const QLocalePrivate *defaultPrivate() static const QLocalePrivate *defaultPrivate()
{ {
if (!default_lp) { if (!default_lp) {
QByteArray lang = qgetenv("LC_ALL"); default_lp = findLocale(qGetLang());
if (lang.isEmpty()) {
lang = qgetenv("LC_CTYPE");
}
if (lang.isEmpty()) {
lang = qgetenv("LANG");
}
default_lp = findLocale(lang);
} }
return default_lp; return default_lp;
} }
@ -340,11 +333,10 @@ QLocale::QLocale(const QString &name)
} }
/*! /*!
Constructs a QLocale object initialized with the default locale. If Constructs a QLocale object initialized with the default locale. This
no default locale was set using setDefaultLocale(), this locale will locale will be the same as the one returned by system().
be the same as the one returned by system().
\sa setDefault() \sa system()
*/ */
QLocale::QLocale() QLocale::QLocale()
@ -363,13 +355,13 @@ QLocale::QLocale()
is \c AnyCountry, the language is used with the most is \c AnyCountry, the language is used with the most
appropriate available country (for example, Germany for German), appropriate available country (for example, Germany for German),
\i If neither the language nor the country are found, QLocale \i If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()). defaults to the system locale (see system()).
\endlist \endlist
The language and country that are actually used can be queried The language and country that are actually used can be queried
using language() and country(). using language() and country().
\sa setDefault() language() country() \sa system() language() country()
*/ */
QLocale::QLocale(Language language, Country country) QLocale::QLocale(Language language, Country country)
@ -401,13 +393,13 @@ QLocale::QLocale(Language language, Country country)
language is used with the first locale that matches the given \a script language is used with the first locale that matches the given \a script
and \a country. and \a country.
\i If neither the language nor the country are found, QLocale \i If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()). defaults to the system locale (see system()).
\endlist \endlist
The language, script and country that are actually used can be queried The language, script and country that are actually used can be queried
using language(), script() and country(). using language(), script() and country().
\sa setDefault() language() script() country() \sa system() language() script() country()
*/ */
QLocale::QLocale(Language language, Script script, Country country) QLocale::QLocale(Language language, Script script, Country country)
@ -473,29 +465,6 @@ QLocale::NumberOptions QLocale::numberOptions() const
return p.numberOptions; return p.numberOptions;
} }
/*!
\nonreentrant
Sets the global default locale to \a locale. These
values are used when a QLocale object is constructed with
no arguments. If this function is not called, the system's
locale is used.
\warning In a multithreaded application, the default locale
should be set at application startup, before any non-GUI threads
are created.
\sa system() c()
*/
void QLocale::setDefault(const QLocale &locale)
{
default_lp = locale.d();
default_number_options = locale.numberOptions();
qt_initLocale(locale.bcp47Name());
}
/*! /*!
Returns the language of this locale. Returns the language of this locale.
@ -1316,7 +1285,6 @@ QString QLocale::toString(double i, char f, int prec) const
\sa c() \sa c()
*/ */
QLocale QLocale::system() QLocale QLocale::system()
{ {
QByteArray lang = qgetenv("LC_ALL"); QByteArray lang = qgetenv("LC_ALL");

View file

@ -1371,7 +1371,6 @@ public:
static QString languageToString(Language language); static QString languageToString(Language language);
static QString countryToString(Country country); static QString countryToString(Country country);
static QString scriptToString(Script script); static QString scriptToString(Script script);
static void setDefault(const QLocale &locale);
static QLocale c() { return QLocale(C); } static QLocale c() { return QLocale(C); }
static QLocale system(); static QLocale system();

View file

@ -36,19 +36,17 @@
\snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 0 \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 0
QLocale supports the concept of a default locale, which is QLocale supports the concept of a system locale, which is
determined from the system's locale settings at application determined from the system's locale settings at application
startup. The default locale can be changed by calling the startup. The default locale has the following effects:
static member setDefault(). Setting the default locale has the
following effects:
\list \list
\i If a QLocale object is constructed with the default constructor, \i If a QLocale object is constructed with the default constructor,
it will use the default locale's settings. it will use the system locale's settings.
\i QString::toInt(), QString::toDouble(), etc., interpret the \i QString::toInt(), QString::toDouble(), etc., interpret the
string according to the default locale. If this fails, it string according to the system locale. If this fails, it
falls back on the "C" locale. falls back on the "C" locale.
\i QString::arg() uses the default locale to format a number when \i QString::arg() uses the system locale to format a number when
its position specifier in the format string contains an 'L', its position specifier in the format string contains an 'L',
e.g. "%L1". e.g. "%L1".
\endlist \endlist
@ -66,7 +64,7 @@
is \c AnyCountry, the language is used with the most is \c AnyCountry, the language is used with the most
appropriate available country (for example, Germany for German), appropriate available country (for example, Germany for German),
\i If neither the language nor the country are found, QLocale \i If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()). defaults to the system locale (see system()).
\endlist \endlist
Use language() and country() to determine the actual language and Use language() and country() to determine the actual language and

View file

@ -5046,8 +5046,7 @@ ushort QString::toUShort(bool *ok, int base) const
This function tries to interpret the string according to the This function tries to interpret the string according to the
current locale. The current locale is determined from the current locale. The current locale is determined from the
system at application startup and can be changed by calling system at application startup. If the string cannot be interpreted
QLocale::setDefault(). If the string cannot be interpreted
according to the current locale, this function falls back according to the current locale, this function falls back
on the "C" locale. on the "C" locale.
@ -5061,7 +5060,7 @@ ushort QString::toUShort(bool *ok, int base) const
\snippet doc/src/snippets/qstring/main.cpp 68 \snippet doc/src/snippets/qstring/main.cpp 68
\sa number() QLocale::setDefault() QLocale::toDouble() trimmed() \sa number() QLocale::system() QLocale::toDouble() trimmed()
*/ */
double QString::toDouble(bool *ok) const double QString::toDouble(bool *ok) const
@ -5837,9 +5836,8 @@ QString QString::arg(const QString &a, int fieldWidth, const QChar &fillChar) co
The '%' can be followed by an 'L', in which case the sequence is The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of \a a. The conversion replaced with a localized representation of \a a. The conversion
uses the default locale, set by QLocale::setDefault(). If no default uses the system locale. If no locale was specified, the "C" locale
locale was specified, the "C" locale is used. The 'L' flag is is used. The 'L' flag is ignored if \a base is not 10.
ignored if \a base is not 10.
\snippet doc/src/snippets/qstring/main.cpp 12 \snippet doc/src/snippets/qstring/main.cpp 12
\snippet doc/src/snippets/qstring/main.cpp 14 \snippet doc/src/snippets/qstring/main.cpp 14
@ -5874,9 +5872,8 @@ QString QString::arg(const QString &a, int fieldWidth, const QChar &fillChar) co
The '%' can be followed by an 'L', in which case the sequence is The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of \a a. The conversion replaced with a localized representation of \a a. The conversion
uses the default locale. The default locale is determined from the uses the default locale. The default locale is determined from the
system's locale settings at application startup. It can be changed system's locale settings at application startup. The 'L' flag is
using QLocale::setDefault(). The 'L' flag is ignored if \a base is ignored if \a base is not 10.
not 10.
\snippet doc/src/snippets/qstring/main.cpp 12 \snippet doc/src/snippets/qstring/main.cpp 12
\snippet doc/src/snippets/qstring/main.cpp 14 \snippet doc/src/snippets/qstring/main.cpp 14
@ -6062,8 +6059,8 @@ QString QString::arg(char a, int fieldWidth, const QChar &fillChar) const
The '%' can be followed by an 'L', in which case the sequence is The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of \a a. The conversion replaced with a localized representation of \a a. The conversion
uses the default locale, set by QLocale::setDefaultLocale(). If no uses the system locale. If no locale was specified, the "C" locale
default locale was specified, the "C" locale is used. is used.
If \a fillChar is '0' (the number 0, ASCII 48), this function will If \a fillChar is '0' (the number 0, ASCII 48), this function will
use the locale's zero to pad. For negative numbers, the zero padding use the locale's zero to pad. For negative numbers, the zero padding

View file

@ -4601,12 +4601,12 @@ QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget
As long as no special locale has been set, this is either As long as no special locale has been set, this is either
the parent's locale or (if this widget is a top level widget), the parent's locale or (if this widget is a top level widget),
the default locale. the system locale.
If the widget displays dates or numbers, these should be formatted If the widget displays dates or numbers, these should be formatted
using the widget's locale. using the widget's locale.
\sa QLocale QLocale::setDefault() \sa QLocale QLocale::system()
*/ */
void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate) void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate)

View file

@ -156,12 +156,10 @@ QLocale QValidator::locale() const
} }
/*! /*!
Sets the \a locale that will be used for the validator. Unless Sets the \a locale that will be used for the validator. If a locale has
setLocale has been called, the validator will use the default not been set, it is the operating system's locale.
locale set with QLocale::setDefault(). If a default locale has not
been set, it is the operating system's locale.
\sa locale() QLocale::setDefault() \sa locale() QLocale::system()
*/ */
void QValidator::setLocale(const QLocale &locale) void QValidator::setLocale(const QLocale &locale)
{ {

View file

@ -739,15 +739,8 @@ void tst_QDate::yearsZeroToNinetyNine()
void tst_QDate::toString() void tst_QDate::toString()
{ {
QDate date(1974,12,1); QDate date(1974,12,1);
QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
QLocale::system().toString(date, QLocale::ShortFormat)); QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate),
QLocale().toString(date, QLocale::ShortFormat));
QLocale::setDefault(QLocale::German);
QCOMPARE(date.toString(Qt::SystemLocaleShortDate),
QLocale::system().toString(date, QLocale::ShortFormat));
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate),
QLocale().toString(date, QLocale::ShortFormat));
} }
void tst_QDate::negativeYear() const void tst_QDate::negativeYear() const

View file

@ -1520,32 +1520,14 @@ void tst_QDateTime::fromString()
QDateTime dt2(QDate(1999, 1, 18), QTime(11, 49, 00)); QDateTime dt2(QDate(1999, 1, 18), QTime(11, 49, 00));
QLocale def; // QDateTime
QLocale::setDefault(QLocale(QLocale::French, QLocale::France));
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2);
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2); QCOMPARE(QDateTime::fromString(dt2.toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2);
// obsolete
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2);
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2);
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::DefaultLocaleLongDate), Qt::DefaultLocaleLongDate), dt2);
QCOMPARE(QDateTime::fromString(dt2.toString(Qt::SystemLocaleLongDate), Qt::SystemLocaleLongDate), dt2); QCOMPARE(QDateTime::fromString(dt2.toString(Qt::SystemLocaleLongDate), Qt::SystemLocaleLongDate), dt2);
// same thing for QDate and QTime // same thing for QDate and QTime
QCOMPARE(QDate::fromString(dt2.date().toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2.date());
QCOMPARE(QDate::fromString(dt2.date().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.date()); QCOMPARE(QDate::fromString(dt2.date().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.date());
QCOMPARE(QDate::fromString(dt2.date().toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2.date());
QCOMPARE(QDate::fromString(dt2.date().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.date()); QCOMPARE(QDate::fromString(dt2.date().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.date());
QCOMPARE(QTime::fromString(dt2.time().toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2.time());
QCOMPARE(QTime::fromString(dt2.time().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.time()); QCOMPARE(QTime::fromString(dt2.time().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.time());
QCOMPARE(QTime::fromString(dt2.time().toString(Qt::DefaultLocaleShortDate), Qt::DefaultLocaleShortDate), dt2.time());
QCOMPARE(QTime::fromString(dt2.time().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.time()); QCOMPARE(QTime::fromString(dt2.time().toString(Qt::SystemLocaleShortDate), Qt::SystemLocaleShortDate), dt2.time());
QLocale::setDefault(def);
} }
void tst_QDateTime::utcOffset() void tst_QDateTime::utcOffset()

View file

@ -167,29 +167,12 @@ void tst_QLocale::ctor()
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(Spanish, LatinAmerica, QLocale::Spanish, QLocale::LatinAmerica) TEST_CTOR(Spanish, LatinAmerica, QLocale::Spanish, QLocale::LatinAmerica)
QLocale::setDefault(QLocale(QLocale::English, QLocale::France));
{
QLocale l;
QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::world);
}
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::world)
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom));
{
QLocale l;
QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom);
}
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
@ -197,17 +180,6 @@ void tst_QLocale::ctor()
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::France));
{
QLocale l;
QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom);
}
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, world, QLocale::English, QLocale::world) TEST_CTOR(English, world, QLocale::English, QLocale::world)
@ -218,18 +190,6 @@ void tst_QLocale::ctor()
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::AnyCountry));
{
QLocale l;
QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom);
}
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, world, QLocale::English, QLocale::world) TEST_CTOR(English, world, QLocale::English, QLocale::world)
@ -266,8 +226,6 @@ void tst_QLocale::ctor()
+ "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \ + "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \
} }
QLocale::setDefault(QLocale(QLocale::C));
QChar c; QChar c;
TEST_CTOR("C", C, AnyCountry) TEST_CTOR("C", C, AnyCountry)
TEST_CTOR("bla", C, AnyCountry) TEST_CTOR("bla", C, AnyCountry)
@ -438,8 +396,6 @@ void tst_QLocale::unixLocaleName()
QCOMPARE(l.name(), QString(exp_name)); \ QCOMPARE(l.name(), QString(exp_name)); \
} }
QLocale::setDefault(QLocale(QLocale::C));
TEST_NAME(C, AnyCountry, "C") TEST_NAME(C, AnyCountry, "C")
TEST_NAME(English, world, "en_001") TEST_NAME(English, world, "en_001")
TEST_NAME(English, AnyCountry, "en_US") TEST_NAME(English, AnyCountry, "en_US")
@ -717,10 +673,6 @@ void tst_QLocale::long_long_conversion_extra()
void tst_QLocale::languageToString() void tst_QLocale::languageToString()
{ {
} }
void tst_QLocale::setDefault()
{
}
*/ */
void tst_QLocale::testInfAndNan() void tst_QLocale::testInfAndNan()

View file

@ -22,7 +22,6 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qstringlist.h> #include <qstringlist.h>
#include <qvariant.h> #include <qvariant.h>
#include <qlocale.h>
#include <locale.h> #include <locale.h>
// This next bit is needed for the NAN and INF in string -> number conversion tests // This next bit is needed for the NAN and INF in string -> number conversion tests
@ -43,12 +42,8 @@ class tst_QStringRef : public QObject
public: public:
tst_QStringRef(); tst_QStringRef();
virtual ~tst_QStringRef();
public slots:
void init();
void cleanup();
private slots: private slots:
void endsWith(); void endsWith();
void startsWith(); void startsWith();
@ -87,19 +82,6 @@ tst_QStringRef::tst_QStringRef()
{ {
} }
tst_QStringRef::~tst_QStringRef()
{
}
void tst_QStringRef::init()
{
}
void tst_QStringRef::cleanup()
{
QLocale::setDefault(QString(QLatin1Char('C')));
}
void tst_QStringRef::length_data() void tst_QStringRef::length_data()
{ {
QTest::addColumn<QString>("s1"); QTest::addColumn<QString>("s1");

View file

@ -652,15 +652,8 @@ void tst_QTime::toString_format()
void tst_QTime::toStringLocale() void tst_QTime::toStringLocale()
{ {
QTime time(18, 30); QTime time(18, 30);
QCOMPARE(time.toString(Qt::SystemLocaleShortDate), QCOMPARE(time.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(time, QLocale::ShortFormat));
QLocale::system().toString(time, QLocale::ShortFormat)); QCOMPARE(time.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(time, QLocale::ShortFormat));
QCOMPARE(time.toString(Qt::DefaultLocaleShortDate),
QLocale().toString(time, QLocale::ShortFormat));
QLocale::setDefault(QLocale::German);
QCOMPARE(time.toString(Qt::SystemLocaleShortDate),
QLocale::system().toString(time, QLocale::ShortFormat));
QCOMPARE(time.toString(Qt::DefaultLocaleShortDate),
QLocale().toString(time, QLocale::ShortFormat));
} }
QTEST_APPLESS_MAIN(tst_QTime) QTEST_APPLESS_MAIN(tst_QTime)