QLocale Class | Qt Core 5.15.18 (original) (raw)

The QLocale class converts between numbers and their string representations in various languages. More...

Member Function Documentation

QString QLocale::toCurrencyString(float value, const QString &symbol = QString()) const

QString QLocale::toCurrencyString(float i, const QString &symbol, int precision) const

This function overloads toCurrencyString().

QLocale::QLocale(const QLocale &other)

Constructs a QLocale object as a copy of other.

QLocale::QLocale(QLocale::Language language, QLocale::Script script, QLocale::Country country)

Constructs a QLocale object with the specified language, script and country.

The language, script and country that are actually used can be queried using language(), script() and country().

This function was introduced in Qt 4.8.

See also setDefault(), language(), script(), and country().

QLocale::QLocale(QLocale::Language language, QLocale::Country country = AnyCountry)

Constructs a QLocale object with the specified language and country.

The language and country that are actually used can be queried using language() and country().

See also setDefault(), language(), and country().

QLocale::QLocale(const QString &name)

Constructs a QLocale object with the specified name, which has the format "language[_script][_country][.codeset][@modifier]" or "C", where:

The separator can be either underscore or a minus sign.

If the string violates the locale format, or language is not a valid ISO 639 code, the "C" locale is used instead. If country is not present, or is not a valid ISO 3166 code, the most appropriate country is chosen for the specified language.

The language, script and country codes are converted to their respective Language, Script and Country enums. After this conversion is performed, the constructor behaves exactly like QLocale(Country, Script, Language).

This constructor is much slower than QLocale(Country, Script, Language).

See also bcp47Name().

QLocale::QLocale()

Constructs a QLocale object initialized with the default locale. If no default locale was set using setDefault(), this locale will be the same as the one returned by system().

See also setDefault().

QLocale &QLocale::operator=(const QLocale &other)

Assigns other to this QLocale object and returns a reference to this QLocale object.

QLocale::~QLocale()

Destructor

QString QLocale::amText() const

Returns the localized name of the "AM" suffix for times specified using the conventions of the 12-hour clock.

This function was introduced in Qt 4.5.

See also pmText().

QString QLocale::bcp47Name() const

Returns the dash-separated language, script and country (and possibly other BCP47 fields) of this locale as a string.

Unlike the uiLanguages() the returned value of the bcp47Name() represents the locale name of the QLocale data but not the language the user-interface should be in.

This function tries to conform the locale name to BCP47.

This function was introduced in Qt 4.8.

See also language(), country(), script(), and uiLanguages().

[static] QLocale QLocale::c()

Returns a QLocale object initialized to the "C" locale.

This locale is based on en_US but with various quirks of its own, such as simplified number formatting and its own date formatting. It implements the POSIX standards that describe the behavior of standard library functions of the "C" programming language.

Among other things, this means its collation order is based on the ASCII values of letters, so that (for case-sensitive sorting) all upper-case letters sort before any lower-case one (rather than each letter's upper- and lower-case forms sorting adjacent to one another, before the next letter's two forms).

See also system().

QLocale QLocale::collation() const

Returns the locale to use for collation.

The result is usually this locale; however, the system locale (which is commonly the default locale) will return the system collation locale. The result is suitable for passing to QCollator's constructor.

This function was introduced in Qt 5.13.

See also QCollator.

QLocale::Country QLocale::country() const

Returns the country of this locale.

See also language(), script(), countryToString(), and bcp47Name().

[static] QString QLocale::countryToString(QLocale::Country country)

Returns a QString containing the name of country.

See also languageToString(), scriptToString(), country(), and bcp47Name().

QString QLocale::createSeparatedList(const QStringList &list) const

Returns a string that represents a join of a given list of strings with a separator defined by the locale.

This function was introduced in Qt 4.8.

QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format = CurrencySymbol) const

Returns a currency symbol according to the format.

This function was introduced in Qt 4.8.

QString QLocale::dateFormat(QLocale::FormatType format = LongFormat) const

Returns the date format used for the current locale.

If format is LongFormat, the format will be elaborate, otherwise it will be short. For example, LongFormat for the en_US locale is dddd, MMMM d, yyyy, ShortFormat is M/d/yy.

This function was introduced in Qt 4.1.

See also QDate::toString() and QDate::fromString().

QString QLocale::dateTimeFormat(QLocale::FormatType format = LongFormat) const

Returns the date time format used for the current locale.

If format is LongFormat, the format will be elaborate, otherwise it will be short. For example, LongFormat for the en_US locale is dddd, MMMM d, yyyy h:mm:ss AP t, ShortFormat is M/d/yy h:mm AP.

This function was introduced in Qt 4.4.

See also QDateTime::toString() and QDateTime::fromString().

QString QLocale::dayName(int day, QLocale::FormatType type = LongFormat) const

Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on), in the format specified by type.

For example, if the locale is en_US and day is 1, LongFormat will return Monday, ShortFormat Mon, and NarrowFormat M.

This function was introduced in Qt 4.2.

See also monthName() and standaloneDayName().

QChar QLocale::decimalPoint() const

Returns the decimal point character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also groupSeparator() and toString().

QChar QLocale::exponential() const

Returns the exponential character of this locale, used to separate exponent from mantissa in some floating-point numeric representations.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also toString(double, char, int).

Qt::DayOfWeek QLocale::firstDayOfWeek() const

Returns the first day of the week according to the current locale.

This function was introduced in Qt 4.8.

QString QLocale::formattedDataSize(qint64 bytes, int precision = 2, QLocale::DataSizeFormats format = DataSizeIecFormat) const

Converts a size in bytes to a human-readable localized string, comprising a number and a quantified unit. The quantifier is chosen such that the number is at least one, and as small as possible. For example if bytes is 16384, precision is 2, and format is DataSizeIecFormat (the default), this function returns "16.00 KiB"; for 1330409069609 bytes it returns "1.21 GiB"; and so on. If format is DataSizeIecFormat or DataSizeTraditionalFormat, the given number of bytes is divided by a power of 1024, with result less than 1024; for DataSizeSIFormat, it is divided by a power of 1000, with result less than 1000. DataSizeIecFormat uses the new IEC standard quantifiers Ki, Mi and so on, whereas DataSizeSIFormat uses the older SI quantifiers k, M, etc., and DataSizeTraditionalFormat abuses them.

This function was introduced in Qt 5.10.

QChar QLocale::groupSeparator() const

Returns the group separator character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also decimalPoint() and toString().

QLocale::Language QLocale::language() const

Returns the language of this locale.

See also script(), country(), languageToString(), and bcp47Name().

[static] QString QLocale::languageToString(QLocale::Language language)

Returns a QString containing the name of language.

See also countryToString(), scriptToString(), and bcp47Name().

[static] QList<QLocale> QLocale::matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country)

Returns a list of valid locale objects that match the given language, script and country.

Getting a list of all locales: QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);

Getting a list of locales suitable for Russia: QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::Russia);

This function was introduced in Qt 4.8.

QLocale::MeasurementSystem QLocale::measurementSystem() const

Returns the measurement system for the locale.

This function was introduced in Qt 4.4.

QString QLocale::monthName(int month, QLocale::FormatType type = LongFormat) const

Returns the localized name of month, in the format specified by type.

For example, if the locale is en_US and month is 1, LongFormat will return January. ShortFormat Jan, and NarrowFormat J.

This function was introduced in Qt 4.2.

See also dayName() and standaloneMonthName().

QString QLocale::name() const

Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two- or three-letter ISO 3166 country code.

Note that even if QLocale object was constructed with an explicit script, name() will not contain it for compatibility reasons. Use bcp47Name() instead if you need a full locale name.

See also QLocale(), language(), script(), country(), and bcp47Name().

QString QLocale::nativeCountryName() const

Returns a native name of the country for the locale. For example "España" for Spanish/Spain locale.

This function was introduced in Qt 4.8.

See also nativeLanguageName() and countryToString().

QString QLocale::nativeLanguageName() const

Returns a native name of the language for the locale. For example "Schwiizertüütsch" for Swiss-German locale.

This function was introduced in Qt 4.8.

See also nativeCountryName() and languageToString().

QChar QLocale::negativeSign() const

Returns the negative sign character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also positiveSign() and toString().

QLocale::NumberOptions QLocale::numberOptions() const

Returns the options related to number conversions for this QLocale instance.

By default, no options are set for the standard locales, except for the "C" locale, which has OmitGroupSeparator set by default.

This function was introduced in Qt 4.2.

See also setNumberOptions(), toString(), and groupSeparator().

QChar QLocale::percent() const

Returns the percent character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also toString().

QString QLocale::pmText() const

Returns the localized name of the "PM" suffix for times specified using the conventions of the 12-hour clock.

This function was introduced in Qt 4.5.

See also amText().

QChar QLocale::positiveSign() const

Returns the positive sign character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.5.

See also negativeSign() and toString().

QString QLocale::quoteString(const QString &str, QLocale::QuotationStyle style = StandardQuotation) const

Returns str quoted according to the current locale using the given quotation style.

This function was introduced in Qt 4.8.

QString QLocale::quoteString(const QStringRef &str, QLocale::QuotationStyle style = StandardQuotation) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QLocale::Script QLocale::script() const

Returns the script of this locale.

This function was introduced in Qt 4.8.

See also language(), country(), languageToString(), scriptToString(), and bcp47Name().

[static] QString QLocale::scriptToString(QLocale::Script script)

Returns a QString containing the name of script.

This function was introduced in Qt 4.8.

See also languageToString(), countryToString(), script(), and bcp47Name().

[static] void QLocale::setDefault(const QLocale &locale)

Sets the global default locale to 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.

Warning: This function is not reentrant.

See also system() and c().

void QLocale::setNumberOptions(QLocale::NumberOptions options)

Sets the options related to number conversions for this QLocale instance.

This function was introduced in Qt 4.2.

See also numberOptions().

QString QLocale::standaloneDayName(int day, QLocale::FormatType type = LongFormat) const

Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on) that is used as a standalone text, in the format specified by type.

If the locale information does not specify the standalone day name then return value is the same as in dayName().

This function was introduced in Qt 4.5.

See also dayName() and standaloneMonthName().

QString QLocale::standaloneMonthName(int month, QLocale::FormatType type = LongFormat) const

Returns the localized name of month that is used as a standalone text, in the format specified by type.

If the locale information doesn't specify the standalone month name then return value is the same as in monthName().

This function was introduced in Qt 4.5.

See also monthName() and standaloneDayName().

void QLocale::swap(QLocale &other)

Swaps locale other with this locale. This operation is very fast and never fails.

This function was introduced in Qt 5.6.

[static] QLocale QLocale::system()

Returns a QLocale object initialized to the system locale.

On Windows and Mac, this locale will use the decimal/grouping characters and date/time formats specified in the system configuration panel.

See also c().

Qt::LayoutDirection QLocale::textDirection() const

Returns the text direction of the language.

This function was introduced in Qt 4.7.

QString QLocale::timeFormat(QLocale::FormatType format = LongFormat) const

Returns the time format used for the current locale.

If format is LongFormat, the format will be elaborate, otherwise it will be short. For example, LongFormat for the en_US locale is h:mm:ss AP t, ShortFormat is h:mm AP.

This function was introduced in Qt 4.1.

See also QTime::toString() and QTime::fromString().

QString QLocale::toCurrencyString(qlonglong value, const QString &symbol = QString()) const

Returns a localized string representation of value as a currency. If the symbol is provided it is used instead of the default currency symbol.

This function was introduced in Qt 4.8.

See also currencySymbol().

QString QLocale::toCurrencyString(qulonglong value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(short value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(ushort value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(int value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(uint value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(double value, const QString &symbol = QString()) const

This is an overloaded function.

This function was introduced in Qt 4.8.

QString QLocale::toCurrencyString(double value, const QString &symbol, int precision) const

This function overloads toCurrencyString().

Returns a localized string representation of value as a currency. If the symbol is provided it is used instead of the default currency symbol. If the precision is provided it is used to set the precision of the currency value.

This function was introduced in Qt 5.7.

See also currencySymbol().

QDate QLocale::toDate(const QString &string, QLocale::FormatType format = LongFormat) const

Parses the date string given in string and returns the date. The format of the date string is chosen according to the format parameter (see dateFormat()).

If the date could not be parsed, returns an invalid date.

This function was introduced in Qt 4.4.

See also dateFormat(), toTime(), toDateTime(), and QDate::fromString().

QDate QLocale::toDate(const QString &string, const QString &format) const

Parses the date string given in string and returns the date. See QDate::fromString() for information on the expressions that can be used with this function.

This function searches month names and the names of the days of the week in the current locale.

If the date could not be parsed, returns an invalid date.

This function was introduced in Qt 4.4.

See also dateFormat(), toTime(), toDateTime(), and QDate::fromString().

QDate QLocale::toDate(const QString &string, QLocale::FormatType format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

QDate QLocale::toDate(const QString &string, const QString &format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

QDateTime QLocale::toDateTime(const QString &string, QLocale::FormatType format = LongFormat) const

Parses the date/time string given in string and returns the time. The format of the date/time string is chosen according to the format parameter (see dateTimeFormat()).

If the string could not be parsed, returns an invalid QDateTime.

This function was introduced in Qt 4.4.

See also dateTimeFormat(), toTime(), toDate(), and QDateTime::fromString().

QDateTime QLocale::toDateTime(const QString &string, const QString &format) const

Parses the date/time string given in string and returns the time. See QDateTime::fromString() for information on the expressions that can be used with this function.

Note: The month and day names used must be given in the user's local language.

If the string could not be parsed, returns an invalid QDateTime. If the string can be parsed and represents an invalid date-time (e.g. in a gap skipped by a time-zone transition), an invalid QDateTime is returned, whose toMSecsSinceEpoch() represents a near-by date-time that is valid. Passing that to fromMSecsSinceEpoch() will produce a valid date-time that isn't faithfully represented by the string parsed.

This function was introduced in Qt 4.4.

See also dateTimeFormat(), toTime(), toDate(), and QDateTime::fromString().

QDateTime QLocale::toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

double QLocale::toDouble(const QString &s, bool *ok = nullptr) const

Returns the double represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function does not fall back to the 'C' locale if the string cannot be interpreted in this locale.

bool ok; double d;

QLocale c(QLocale::C); d = c.toDouble("1234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble("1,234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble("1234,56", &ok); // ok == false, d == 0

QLocale german(QLocale::German); d = german.toDouble("1234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble("1.234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble("1234.56", &ok); // ok == false, d == 0

d = german.toDouble("1.234", &ok); // ok == true, d == 1234.0

Notice that the last conversion returns 1234.0, because '.' is the thousands group separator in the German locale.

This function ignores leading and trailing whitespace.

See also toFloat(), toInt(), and toString().

double QLocale::toDouble(const QStringRef &s, bool *ok = nullptr) const

Returns the double represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function does not fall back to the 'C' locale if the string cannot be interpreted in this locale.

bool ok; double d;

QLocale c(QLocale::C); d = c.toDouble("1234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble("1,234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble("1234,56", &ok); // ok == false, d == 0

QLocale german(QLocale::German); d = german.toDouble("1234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble("1.234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble("1234.56", &ok); // ok == false, d == 0

d = german.toDouble("1.234", &ok); // ok == true, d == 1234.0

Notice that the last conversion returns 1234.0, because '.' is the thousands group separator in the German locale.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toFloat(), toInt(), and toString().

double QLocale::toDouble(QStringView s, bool *ok = nullptr) const

Returns the double represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

Unlike QString::toDouble(), this function does not fall back to the "C" locale if the string cannot be interpreted in this locale.

bool ok; double d;

QLocale c(QLocale::C); d = c.toDouble(u"1234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble(u"1,234.56", &ok); // ok == true, d == 1234.56 d = c.toDouble(u"1234,56", &ok); // ok == false, d == 0

QLocale german(QLocale::German); d = german.toDouble(u"1234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble(u"1.234,56", &ok); // ok == true, d == 1234.56 d = german.toDouble(u"1234.56", &ok); // ok == false, d == 0

d = german.toDouble(u"1.234", &ok); // ok == true, d == 1234.0

Notice that the last conversion returns 1234.0, because '.' is the thousands group separator in the German locale.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toFloat(), toInt(), and toString().

float QLocale::toFloat(const QString &s, bool *ok = nullptr) const

Returns the float represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function does not fall back to the 'C' locale if the string cannot be interpreted in this locale.

This function ignores leading and trailing whitespace.

See also toDouble(), toInt(), and toString().

float QLocale::toFloat(const QStringRef &s, bool *ok = nullptr) const

Returns the float represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function does not fall back to the 'C' locale if the string cannot be interpreted in this locale.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toDouble(), toInt(), and toString().

float QLocale::toFloat(QStringView s, bool *ok = nullptr) const

Returns the float represented by the localized string s.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toDouble(), toInt(), and toString().

int QLocale::toInt(const QString &s, bool *ok = nullptr) const

Returns the int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toUInt() and toString().

int QLocale::toInt(const QStringRef &s, bool *ok = nullptr) const

Returns the int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toUInt() and toString().

int QLocale::toInt(QStringView s, bool *ok = nullptr) const

Returns the int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toUInt() and toString().

long QLocale::toLong(const QString &s, bool *ok = nullptr) const

Returns the long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toInt(), toULong(), toDouble(), and toString().

long QLocale::toLong(const QStringRef &s, bool *ok = nullptr) const

Returns the long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toInt(), toULong(), toDouble(), and toString().

long QLocale::toLong(QStringView s, bool *ok = nullptr) const

Returns the long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toInt(), toULong(), toDouble(), and toString().

qlonglong QLocale::toLongLong(const QString &s, bool *ok = nullptr) const

Returns the long long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toInt(), toULongLong(), toDouble(), and toString().

qlonglong QLocale::toLongLong(const QStringRef &s, bool *ok = nullptr) const

Returns the long long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toInt(), toULongLong(), toDouble(), and toString().

qlonglong QLocale::toLongLong(QStringView s, bool *ok = nullptr) const

Returns the long long int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toInt(), toULongLong(), toDouble(), and toString().

QString QLocale::toLower(const QString &str) const

Returns a lowercase copy of str.

If Qt Core is using the ICU libraries, they will be used to perform the transformation according to the rules of the current locale. Otherwise the conversion may be done in a platform-dependent manner, with QString::toLower() as a generic fallback.

This function was introduced in Qt 4.8.

See also QString::toLower().

short QLocale::toShort(const QString &s, bool *ok = nullptr) const

Returns the short int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toUShort() and toString().

short QLocale::toShort(const QStringRef &s, bool *ok = nullptr) const

Returns the short int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toUShort() and toString().

short QLocale::toShort(QStringView s, bool *ok = nullptr) const

Returns the short int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toUShort() and toString().

QString QLocale::toString(qlonglong i) const

Returns a localized string representation of i.

See also toLongLong(), numberOptions(), zeroDigit(), and positiveSign().

QString QLocale::toString(qulonglong i) const

This is an overloaded function.

See also toULongLong(), numberOptions(), zeroDigit(), and positiveSign().

QString QLocale::toString(long i) const

This is an overloaded function.

See also toLong().

QString QLocale::toString(ulong i) const

This is an overloaded function.

See also toULong().

QString QLocale::toString(short i) const

This is an overloaded function.

See also toShort().

QString QLocale::toString(ushort i) const

This is an overloaded function.

See also toUShort().

QString QLocale::toString(int i) const

This is an overloaded function.

See also toInt().

QString QLocale::toString(uint i) const

This is an overloaded function.

See also toUInt().

QString QLocale::toString(double i, char f = 'g', int prec = 6) const

This is an overloaded function.

f and prec have the same meaning as in QString::number(double, char, int).

See also toDouble(), numberOptions(), exponential(), decimalPoint(), zeroDigit(), positiveSign(), and percent().

QString QLocale::toString(float i, char f = 'g', int prec = 6) const

This is an overloaded function.

f and prec have the same meaning as in QString::number(double, char, int).

See also toDouble().

QString QLocale::toString(const QDate &date, const QString &format) const

Returns a localized string representation of the given date in the specified format. If format is an empty string, an empty string is returned.

See also QDate::toString().

QString QLocale::toString(const QTime &time, const QString &format) const

Returns a localized string representation of the given time according to the specified format. If format is an empty string, an empty string is returned.

See also QTime::toString().

QString QLocale::toString(const QDateTime &dateTime, const QString &format) const

Returns a localized string representation of the given dateTime according to the specified format. If format is an empty string, an empty string is returned.

This function was introduced in Qt 4.4.

See also QDateTime::toString(), QDate::toString(), and QTime::toString().

QString QLocale::toString(const QDate &date, QStringView format) const

This is an overloaded function.

This function was introduced in Qt 5.10.

QString QLocale::toString(const QTime &time, QStringView format) const

Returns a localized string representation of the given time according to the specified format. If format is an empty string, an empty string is returned.

This function was introduced in Qt 4.5.

See also QTime::toString().

QString QLocale::toString(const QDateTime &dateTime, QStringView format) const

This is an overloaded function.

This function was introduced in Qt 5.10.

QString QLocale::toString(const QDate &date, QLocale::FormatType format = LongFormat) const

This is an overloaded function.

This function was introduced in Qt 4.5.

QString QLocale::toString(const QTime &time, QLocale::FormatType format = LongFormat) const

Returns a localized string representation of the given time in the specified format (see timeFormat()).

QString QLocale::toString(const QDateTime &dateTime, QLocale::FormatType format = LongFormat) const

This is an overloaded function.

This function was introduced in Qt 4.4.

QString QLocale::toString(const QDate &date, QStringView format, QCalendar cal) const

Returns a localized string representation of the given date in the specified format, optionally for a specified calendar cal. If format is an empty string, an empty string is returned.

This function was introduced in Qt 5.14.

See also QDate::toString().

QString QLocale::toString(const QDate &date, QLocale::FormatType format, QCalendar cal) const

Returns a localized string representation of the given date according to the specified format (see dateFormat()), optionally for a specified calendar cal.

Note: Some locales may use formats that limit the range of years they can represent.

This function was introduced in Qt 5.14.

QString QLocale::toString(const QDateTime &dateTime, QLocale::FormatType format, QCalendar cal) const

Returns a localized string representation of the given dateTime according to the specified format (see dateTimeFormat()), optionally for a specified calendar cal.

Note: Some locales may use formats that limit the range of years they can represent.

This function was introduced in Qt 5.14.

QString QLocale::toString(const QDateTime &dateTime, QStringView format, QCalendar cal) const

Returns a localized string representation of the given dateTime according to the specified format, optionally for a specified calendar cal. If format is an empty string, an empty string is returned.

This function was introduced in Qt 5.14.

See also QDateTime::toString(), QDate::toString(), and QTime::toString().

QTime QLocale::toTime(const QString &string, QLocale::FormatType format = LongFormat) const

Parses the time string given in string and returns the time. The format of the time string is chosen according to the format parameter (see timeFormat()).

If the time could not be parsed, returns an invalid time.

This function was introduced in Qt 4.4.

See also timeFormat(), toDate(), toDateTime(), and QTime::fromString().

QTime QLocale::toTime(const QString &string, const QString &format) const

Parses the time string given in string and returns the time. See QTime::fromString() for information on what is a valid format string.

If the time could not be parsed, returns an invalid time.

This function was introduced in Qt 4.4.

See also timeFormat(), toDate(), toDateTime(), and QTime::fromString().

uint QLocale::toUInt(const QString &s, bool *ok = nullptr) const

Returns the unsigned int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toInt() and toString().

uint QLocale::toUInt(const QStringRef &s, bool *ok = nullptr) const

Returns the unsigned int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toInt() and toString().

uint QLocale::toUInt(QStringView s, bool *ok = nullptr) const

Returns the unsigned int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toInt() and toString().

ulong QLocale::toULong(const QString &s, bool *ok = nullptr) const

Returns the unsigned long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toLong(), toInt(), toDouble(), and toString().

ulong QLocale::toULong(const QStringRef &s, bool *ok = nullptr) const

Returns the unsigned long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toLong(), toInt(), toDouble(), and toString().

ulong QLocale::toULong(QStringView s, bool *ok = nullptr) const

Returns the unsigned long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

See also toLong(), toInt(), toDouble(), and toString().

qulonglong QLocale::toULongLong(const QString &s, bool *ok = nullptr) const

Returns the unsigned long long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toLongLong(), toInt(), toDouble(), and toString().

qulonglong QLocale::toULongLong(const QStringRef &s, bool *ok = nullptr) const

Returns the unsigned long long int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toLongLong(), toInt(), toDouble(), and toString().

qulonglong QLocale::toULongLong(QStringView s, bool *ok = nullptr) const

Returns the unsigned long long int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toLongLong(), toInt(), toDouble(), and toString().

ushort QLocale::toUShort(const QString &s, bool *ok = nullptr) const

Returns the unsigned short int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also toShort() and toString().

ushort QLocale::toUShort(const QStringRef &s, bool *ok = nullptr) const

Returns the unsigned short int represented by the localized string s.

If the conversion fails the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toShort() and toString().

ushort QLocale::toUShort(QStringView s, bool *ok = nullptr) const

Returns the unsigned short int represented by the localized string s.

If the conversion fails, the function returns 0.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toShort() and toString().

QString QLocale::toUpper(const QString &str) const

Returns an uppercase copy of str.

If Qt Core is using the ICU libraries, they will be used to perform the transformation according to the rules of the current locale. Otherwise the conversion may be done in a platform-dependent manner, with QString::toUpper() as a generic fallback.

Note: In some cases the uppercase form of a string may be longer than the original.

This function was introduced in Qt 4.8.

See also QString::toUpper().

QStringList QLocale::uiLanguages() const

Returns an ordered list of locale names for translation purposes in preference order (like "en-Latn-US", "en-US", "en").

The return value represents locale names that the user expects to see the UI translation in.

Most like you do not need to use this function directly, but just pass the QLocale object to the QTranslator::load() function.

The first item in the list is the most preferred one.

This function was introduced in Qt 4.8.

See also QTranslator and bcp47Name().

QList<Qt::DayOfWeek> QLocale::weekdays() const

Returns a list of days that are considered weekdays according to the current locale.

This function was introduced in Qt 4.8.

QChar QLocale::zeroDigit() const

Returns the zero digit character of this locale.

Note: This function shall change to return a QString instead of QChar in Qt6. Callers are encouraged to exploit the QString(QChar) constructor to convert early in preparation for this.

This function was introduced in Qt 4.1.

See also toString().

bool QLocale::operator!=(const QLocale &other) const

Returns true if the QLocale object is not the same as the other locale specified; otherwise returns false.

bool QLocale::operator==(const QLocale &other) const

Returns true if the QLocale object is the same as the other locale specified; otherwise returns false.