[go: up one dir, main page]

QLocale Class

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

Header: #include <QLocale>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

This class is equality-comparable.

Note: All functions in this class are reentrant with the following exceptions:

Public Types

enum Country { AnyCountry, AnyTerritory, Afghanistan, AlandIslands, Albania, …, Zimbabwe }
enum CurrencySymbolFormat { CurrencyIsoCode, CurrencySymbol, CurrencyDisplayName }
enum DataSizeFormat { DataSizeIecFormat, DataSizeTraditionalFormat, DataSizeSIFormat }
flags DataSizeFormats
enum FloatingPointPrecisionOption { FloatingPointShortest }
enum FormatType { LongFormat, ShortFormat, NarrowFormat }
enum Language { AnyLanguage, C, Abkhazian, Afan, Afar, …, Zulu }
enum LanguageCodeType { ISO639Part1, ISO639Part2B, ISO639Part2T, ISO639Part3, LegacyLanguageCode, …, AnyLanguageCode }
flags LanguageCodeTypes
enum MeasurementSystem { MetricSystem, ImperialUSSystem, ImperialUKSystem, ImperialSystem }
enum NumberOption { DefaultNumberOptions, OmitGroupSeparator, RejectGroupSeparator, OmitLeadingZeroInExponent, RejectLeadingZeroInExponent, …, RejectTrailingZeroesAfterDot }
flags NumberOptions
enum QuotationStyle { StandardQuotation, AlternateQuotation }
enum Script { AnyScript, AdlamScript, AhomScript, AnatolianHieroglyphsScript, ArabicScript, …, YiScript }
(since 6.7) enum class TagSeparator { Dash, Underscore }
Territory

Public Functions

QLocale()
(since 6.3) QLocale(QStringView name)
QLocale(QLocale::Language language, QLocale::Territory territory)
QLocale(QLocale::Language language, QLocale::Script script = AnyScript, QLocale::Territory territory = AnyTerritory)
QLocale(const QString &name)
QLocale(const QLocale &other)
~QLocale()
QString amText() const
QString bcp47Name(QLocale::TagSeparator separator = TagSeparator::Dash) const
QLocale collation() const
QString createSeparatedList(const QStringList &list) const
QString currencySymbol(QLocale::CurrencySymbolFormat format = CurrencySymbol) const
QString dateFormat(QLocale::FormatType format = LongFormat) const
QString dateTimeFormat(QLocale::FormatType format = LongFormat) const
QString dayName(int day, QLocale::FormatType type = LongFormat) const
QString decimalPoint() const
QString exponential() const
Qt::DayOfWeek firstDayOfWeek() const
QString formattedDataSize(qint64 bytes, int precision = 2, QLocale::DataSizeFormats format = DataSizeIecFormat) const
QString groupSeparator() const
QLocale::Language language() const
QLocale::MeasurementSystem measurementSystem() const
QString monthName(int month, QLocale::FormatType type = LongFormat) const
QString name(QLocale::TagSeparator separator = TagSeparator::Underscore) const
QString nativeLanguageName() const
(since 6.2) QString nativeTerritoryName() const
QString negativeSign() const
QLocale::NumberOptions numberOptions() const
QString percent() const
QString pmText() const
QString positiveSign() const
QString quoteString(const QString &str, QLocale::QuotationStyle style = StandardQuotation) const
(since 6.0) QString quoteString(QStringView str, QLocale::QuotationStyle style = StandardQuotation) const
QLocale::Script script() const
void setNumberOptions(QLocale::NumberOptions options)
QString standaloneDayName(int day, QLocale::FormatType type = LongFormat) const
QString standaloneMonthName(int month, QLocale::FormatType type = LongFormat) const
void swap(QLocale &other)
(since 6.2) QLocale::Territory territory() const
Qt::LayoutDirection textDirection() const
QString timeFormat(QLocale::FormatType format = LongFormat) const
QString toCurrencyString(qlonglong value, const QString &symbol = QString()) const
QString toCurrencyString(int value, const QString &symbol = QString()) const
QString toCurrencyString(qulonglong value, const QString &symbol = QString()) const
QString toCurrencyString(short value, const QString &symbol = QString()) const
QString toCurrencyString(uint value, const QString &symbol = QString()) const
QString toCurrencyString(ushort value, const QString &symbol = QString()) const
QString toCurrencyString(double value, const QString &symbol = QString(), int precision = -1) const
QString toCurrencyString(float i, const QString &symbol = QString(), int precision = -1) const
QDate toDate(const QString &string, QLocale::FormatType format = LongFormat, int baseYear = DefaultTwoDigitBaseYear) const
QDate toDate(const QString &string, const QString &format, int baseYear = DefaultTwoDigitBaseYear) const
QDate toDate(const QString &string, QLocale::FormatType format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const
QDate toDate(const QString &string, const QString &format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const
QDateTime toDateTime(const QString &string, QLocale::FormatType format = LongFormat, int baseYear = DefaultTwoDigitBaseYear) const
QDateTime toDateTime(const QString &string, const QString &format, int baseYear = DefaultTwoDigitBaseYear) const
QDateTime toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const
QDateTime toDateTime(const QString &string, const QString &format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const
double toDouble(QStringView s, bool *ok = nullptr) const
double toDouble(const QString &s, bool *ok = nullptr) const
float toFloat(QStringView s, bool *ok = nullptr) const
float toFloat(const QString &s, bool *ok = nullptr) const
int toInt(QStringView s, bool *ok = nullptr) const
int toInt(const QString &s, bool *ok = nullptr) const
long toLong(QStringView s, bool *ok = nullptr) const
long toLong(const QString &s, bool *ok = nullptr) const
qlonglong toLongLong(QStringView s, bool *ok = nullptr) const
qlonglong toLongLong(const QString &s, bool *ok = nullptr) const
QString toLower(const QString &str) const
short toShort(QStringView s, bool *ok = nullptr) const
short toShort(const QString &s, bool *ok = nullptr) const
QString toString(qlonglong i) const
QString toString(QDate date, const QString &format) const
QString toString(QTime time, QLocale::FormatType format = LongFormat) const
QString toString(QTime time, QStringView format) const
QString toString(QTime time, const QString &format) const
QString toString(const QDateTime &dateTime, const QString &format) const
QString toString(QDate date, QLocale::FormatType format, QCalendar cal) const
QString toString(QDate date, QStringView format, QCalendar cal) const
QString toString(const QDateTime &dateTime, QLocale::FormatType format, QCalendar cal) const
QString toString(const QDateTime &dateTime, QStringView format, QCalendar cal) const
QString toString(int i) const
QString toString(long i) const
QString toString(qulonglong i) const
QString toString(short i) const
QString toString(uint i) const
QString toString(ulong i) const
QString toString(ushort i) const
QString toString(QDate date, QLocale::FormatType format = LongFormat) const
QString toString(QDate date, QStringView format) const
QString toString(const QDateTime &dateTime, QLocale::FormatType format = LongFormat) const
QString toString(const QDateTime &dateTime, QStringView format) const
QString toString(double f, char format = 'g', int precision = 6) const
QString toString(float f, char format = 'g', int precision = 6) const
QTime toTime(const QString &string, QLocale::FormatType format = LongFormat) const
QTime toTime(const QString &string, const QString &format) const
uint toUInt(QStringView s, bool *ok = nullptr) const
uint toUInt(const QString &s, bool *ok = nullptr) const
ulong toULong(QStringView s, bool *ok = nullptr) const
ulong toULong(const QString &s, bool *ok = nullptr) const
qulonglong toULongLong(QStringView s, bool *ok = nullptr) const
qulonglong toULongLong(const QString &s, bool *ok = nullptr) const
ushort toUShort(QStringView s, bool *ok = nullptr) const
ushort toUShort(const QString &s, bool *ok = nullptr) const
QString toUpper(const QString &str) const
QStringList uiLanguages(QLocale::TagSeparator separator = TagSeparator::Dash) const
QList<Qt::DayOfWeek> weekdays() const
QString zeroDigit() const
QLocale &operator=(const QLocale &other)

Static Public Members

(since 6.7) const int DefaultTwoDigitBaseYear
QLocale c()
(since 6.3) QLocale::Language codeToLanguage(QStringView languageCode, QLocale::LanguageCodeTypes codeTypes = AnyLanguageCode)
(since 6.1) QLocale::Script codeToScript(QStringView scriptCode)
(since 6.2) QLocale::Territory codeToTerritory(QStringView territoryCode)
(since 6.3) QString languageToCode(QLocale::Language language, QLocale::LanguageCodeTypes codeTypes = AnyLanguageCode)
QString languageToString(QLocale::Language language)
QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Territory territory)
(since 6.1) QString scriptToCode(QLocale::Script script)
QString scriptToString(QLocale::Script script)
void setDefault(const QLocale &locale)
QLocale system()
(since 6.2) QString territoryToCode(QLocale::Territory territory)
(since 6.2) QString territoryToString(QLocale::Territory territory)
size_t qHash(const QLocale &key, size_t seed = 0)
bool operator!=(const QLocale &lhs, const QLocale &rhs)
bool operator==(const QLocale &lhs, const QLocale &rhs)

Detailed Description

QLocale is constructed for a specified language, optional script and territory. It offers various facilities for formatting data as text, localized appropriately, and for reading data out of localized text.

Example:

QLocale egyptian(QLocale::Arabic, QLocale::Egypt);
QString s1 = egyptian.toString(1.571429E+07, 'e');
QString s2 = egyptian.toString(10);

double d = egyptian.toDouble(s1);
int i = egyptian.toInt(s2);

QLocale supports the concept of a default locale, which is determined from the system's locale settings at application startup. The default locale can be changed by calling the static member setDefault(). Setting the default locale has the following effects:

  • If a QLocale object is constructed with the default constructor, it will use the default locale's settings.
  • QString::arg() uses the default locale to format a number when its position specifier in the format string contains an 'L', e.g. "%L1".

The following example illustrates how to use QLocale directly:

bool ok;
double d;

QLocale::setDefault(QLocale::C);      // uses '.' as a decimal point
QLocale cLocale;                      // default-constructed C locale
d = cLocale.toDouble("1234,56", &ok); // ok == false, d == 0
d = cLocale.toDouble("1234.56", &ok); // ok == true,  d == 1234.56

QLocale::setDefault(QLocale::German); // uses ',' as a decimal point
QLocale german;                       // default-constructed German locale
d = german.toDouble("1234,56", &ok);  // ok == true,  d == 1234.56
d = german.toDouble("1234.56", &ok);  // ok == false, d == 0

QLocale::setDefault(QLocale::English);
// Default locale now uses ',' as a group separator.
QString str = QString("%1 %L2 %L3").arg(12345).arg(12345).arg(12345, 0, 16);
// str == "12345 12,345 3039"

An alternative method for constructing a QLocale object is by specifying the locale name.

QLocale korean("ko");
QLocale swiss("de_CH");

This constructor reads the language, script and/or territory from the given name, accepting either uderscore or dash as separator (and ignoring any trailing .codeset or @variant suffix).

Note: For the current keyboard input locale take a look at QInputMethod::locale().

QLocale's data is based on Common Locale Data Repository v45.

Matching combinations of language, script and territory

QLocale has data, derived from CLDR, for many combinations of language, script and territory, but not all. If it is constructed with all three of these key values specified (treating AnyLanguage, AnyScript or AnyTerritory as unspecified) and QLocale has data for the given combination, this data is used. Otherwise, QLocale does its best to find a sensible combination of language, script and territory, for which it does have data, that matches those that were specified.

The CLDR provides tables of likely combinations, which are used to fill in any unspecified key or keys; if QLocale has data for the result of such a likely combination, that is used. If no language is specified, and none can be determined from script and territory, or if QLocale has no data for the language, the "C" locale (when reading the keys from a string) or default locale (otherwise) is used.

When QLocale has no data for the keys specified, with likely keys filled in where unspecified, but does have data for the resulting language, a fall-back is sought, based on ignoring either territory, script or both (in that order). This results in a QLocale which may not match what was asked for, but provides localization that's as suitable as the available data permits, for the keys specified.

Use language(), script() and territory() to determine the actual keys used.

See also QString::arg() and QInputMethod::locale().

Member Type Documentation

enum QLocale::Country

This enumerated type is used to identify a territory.

An individual territory may be a province of a country, a country (by far the most common case) or a larger geographic entity, to which some localization details are specific.

ConstantValueDescription
QLocale::AnyCountryAnyTerritoryOsbolete alias for AnyTerritory
QLocale::AnyTerritory (since Qt 6.2)0 
QLocale::Afghanistan1 
QLocale::AlandIslands2 
QLocale::Albania3 
QLocale::Algeria4 
QLocale::AmericanSamoa5 
QLocale::Andorra6 
QLocale::Angola7 
QLocale::Anguilla8 
QLocale::Antarctica9 
QLocale::AntiguaAndBarbuda10 
QLocale::Argentina11 
QLocale::Armenia12 
QLocale::Aruba13 
QLocale::AscensionIsland14 
QLocale::Australia15 
QLocale::Austria16 
QLocale::Azerbaijan17 
QLocale::Bahamas18 
QLocale::Bahrain19 
QLocale::Bangladesh20 
QLocale::Barbados21 
QLocale::Belarus22 
QLocale::Belgium23 
QLocale::Belize24 
QLocale::Benin25 
QLocale::Bermuda26 
QLocale::Bhutan27 
QLocale::Bolivia28 
QLocale::BonaireCaribbeanNetherlands 
QLocale::BosniaAndHerzegowinaBosniaAndHerzegovinaObsolete, use BosniaAndHerzegovina instead
QLocale::BosniaAndHerzegovina (since Qt 6.0)29 
QLocale::Botswana30 
QLocale::BouvetIsland31 
QLocale::Brazil32 
QLocale::BritishIndianOceanTerritory33 
QLocale::BritishVirginIslands34 
QLocale::Brunei35 
QLocale::Bulgaria36 
QLocale::BurkinaFaso37 
QLocale::Burundi38 
QLocale::Cambodia39 
QLocale::Cameroon40 
QLocale::Canada41 
QLocale::CanaryIslands42 
QLocale::CaribbeanNetherlands44 
QLocale::CapeVerde43 
QLocale::CaymanIslands45 
QLocale::CentralAfricanRepublic46 
QLocale::CeutaAndMelilla47 
QLocale::Chad48 
QLocale::Chile49 
QLocale::China50 
QLocale::ChristmasIsland51 
QLocale::ClippertonIsland52 
QLocale::CocosIslands53 
QLocale::Colombia54 
QLocale::Comoros55 
QLocale::CongoBrazzaville56 
QLocale::CongoKinshasa57 
QLocale::CookIslands58 
QLocale::CostaRica59 
QLocale::Croatia60 
QLocale::Cuba61 
QLocale::Curacao (since Qt 6.0)62 
QLocale::CuraSaoCuracaoObsolete, use Curacao instead
QLocale::Cyprus63 
QLocale::Czechia (since Qt 6.0)64 
QLocale::CzechRepublicCzechiaObsolete, use Czechia instead
QLocale::DemocraticRepublicOfCongoCongoKinshasaObsolete, use CongoKinshasa instead
QLocale::DemocraticRepublicOfKoreaNorthKoreaObsolete, use NorthKorea instead
QLocale::Denmark65 
QLocale::DiegoGarcia66 
QLocale::Djibouti67 
QLocale::Dominica68 
QLocale::DominicanRepublic69 
QLocale::EastTimorTimorLeste 
QLocale::Ecuador70 
QLocale::Egypt71 
QLocale::ElSalvador72 
QLocale::EquatorialGuinea73 
QLocale::Eritrea74 
QLocale::Estonia75 
QLocale::Eswatini76 
QLocale::Ethiopia77 
QLocale::EuropeanUnion (since Qt 5.7)79 
QLocale::Europe (since Qt 5.12)78 
QLocale::FalklandIslands80 
QLocale::FaroeIslands81 
QLocale::Fiji82 
QLocale::Finland83 
QLocale::France84 
QLocale::FrenchGuiana85 
QLocale::FrenchPolynesia86 
QLocale::FrenchSouthernTerritories87 
QLocale::Gabon88 
QLocale::Gambia89 
QLocale::Georgia90 
QLocale::Germany91 
QLocale::Ghana92 
QLocale::Gibraltar93 
QLocale::Greece94 
QLocale::Greenland95 
QLocale::Grenada96 
QLocale::Guadeloupe97 
QLocale::Guam98 
QLocale::Guatemala99 
QLocale::Guernsey100 
QLocale::Guinea102 
QLocale::GuineaBissau101 
QLocale::Guyana103 
QLocale::Haiti104 
QLocale::HeardAndMcDonaldIslands105 
QLocale::Honduras106 
QLocale::HongKong107 
QLocale::Hungary108 
QLocale::Iceland109 
QLocale::India110 
QLocale::Indonesia111 
QLocale::Iran112 
QLocale::Iraq113 
QLocale::Ireland114 
QLocale::IsleOfMan115 
QLocale::Israel116 
QLocale::Italy117 
QLocale::IvoryCoast118 
QLocale::Jamaica119 
QLocale::Japan120 
QLocale::Jersey121 
QLocale::Jordan122 
QLocale::Kazakhstan123 
QLocale::Kenya124 
QLocale::Kiribati125 
QLocale::Kosovo (since Qt 5.2)126 
QLocale::Kuwait127 
QLocale::Kyrgyzstan128 
QLocale::Laos129 
QLocale::LatinAmerica130 
QLocale::LatinAmericaAndTheCaribbeanLatinAmericaObsolete, use LatinAmerica instead
QLocale::Latvia131 
QLocale::Lebanon132 
QLocale::Lesotho133 
QLocale::Liberia134 
QLocale::Libya135 
QLocale::Liechtenstein136 
QLocale::Lithuania137 
QLocale::Luxembourg138 
QLocale::Macao139 
QLocale::MacauMacao 
QLocale::Macedonia140 
QLocale::Madagascar141 
QLocale::Malawi142 
QLocale::Malaysia143 
QLocale::Maldives144 
QLocale::Mali145 
QLocale::Malta146 
QLocale::MarshallIslands147 
QLocale::Martinique148 
QLocale::Mauritania149 
QLocale::Mauritius150 
QLocale::Mayotte151 
QLocale::Mexico152 
QLocale::Micronesia153 
QLocale::Moldova154 
QLocale::Monaco155 
QLocale::Mongolia156 
QLocale::Montenegro157 
QLocale::Montserrat158 
QLocale::Morocco159 
QLocale::Mozambique160 
QLocale::Myanmar161 
QLocale::Namibia162 
QLocale::NauruCountryNauruTerritoryOsbolete alias for NauruTerritory
QLocale::NauruTerritory (since Qt 6.2)163 
QLocale::Nepal164 
QLocale::Netherlands165 
QLocale::NewCaledonia166 
QLocale::NewZealand167 
QLocale::Nicaragua168 
QLocale::Niger170 
QLocale::Nigeria169 
QLocale::Niue171 
QLocale::NorfolkIsland172 
QLocale::NorthernMarianaIslands173 
QLocale::NorthKorea174 
QLocale::Norway175 
QLocale::Oman176 
QLocale::OutlyingOceania (since Qt 5.7)177 
QLocale::Pakistan178 
QLocale::Palau179 
QLocale::PalestinianTerritories180 
QLocale::Panama181 
QLocale::PapuaNewGuinea182 
QLocale::Paraguay183 
QLocale::PeoplesRepublicOfCongoCongoBrazzavilleObsolete, use CongoBrazzaville instead
QLocale::Peru184 
QLocale::Philippines185 
QLocale::Pitcairn186 
QLocale::Poland187 
QLocale::Portugal188 
QLocale::PuertoRico189 
QLocale::Qatar190 
QLocale::RepublicOfKoreaSouthKoreaObsolete, use SouthKorea instead
QLocale::Reunion191 
QLocale::Romania192 
QLocale::RussianFederationRussia 
QLocale::Russia193 
QLocale::Rwanda194 
QLocale::SaintBarthelemy195 
QLocale::SaintHelena196 
QLocale::SaintKittsAndNevis197 
QLocale::SaintLucia198 
QLocale::SaintMartin199 
QLocale::SaintPierreAndMiquelon200 
QLocale::SaintVincentAndGrenadines201 
QLocale::SaintVincentAndTheGrenadinesSaintVincentAndGrenadines 
QLocale::Samoa202 
QLocale::SanMarino203 
QLocale::SaoTomeAndPrincipe204 
QLocale::SaudiArabia205 
QLocale::Senegal206 
QLocale::Serbia207 
QLocale::Seychelles208 
QLocale::SierraLeone209 
QLocale::Singapore210 
QLocale::SintMaarten211 
QLocale::Slovakia212 
QLocale::Slovenia213 
QLocale::SolomonIslands214 
QLocale::Somalia215 
QLocale::SouthAfrica216 
QLocale::SouthGeorgiaAndSouthSandwichIslands217 
QLocale::SouthGeorgiaAndTheSouthSandwichIslandsSouthGeorgiaAndSouthSandwichIslands 
QLocale::SouthKorea218 
QLocale::SouthSudan219 
QLocale::Spain220 
QLocale::SriLanka221 
QLocale::Sudan222 
QLocale::Suriname223 
QLocale::SvalbardAndJanMayen224 
QLocale::SvalbardAndJanMayenIslandsSvalbardAndJanMayen 
QLocale::SwazilandEswatini 
QLocale::Sweden225 
QLocale::Switzerland226 
QLocale::Syria227 
QLocale::SyrianArabRepublicSyriaObsolete, use Syria instead
QLocale::Taiwan228 
QLocale::Tajikistan229 
QLocale::Tanzania230 
QLocale::Thailand231 
QLocale::TimorLeste232 
QLocale::Togo233 
QLocale::TokelauCountryTokelauTerritoryOsbolete alias for TokelauTerritory
QLocale::TokelauTerritory (since Qt 6.2)234 
QLocale::Tonga235 
QLocale::TrinidadAndTobago236 
QLocale::TristanDaCunha237 
QLocale::Tunisia238 
QLocale::Turkey239 
QLocale::Turkmenistan240 
QLocale::TurksAndCaicosIslands241 
QLocale::TuvaluCountryTuvaluTerritoryOsbolete alias for TuvaluTerritory
QLocale::TuvaluTerritory (since Qt 6.2)242 
QLocale::Uganda243 
QLocale::Ukraine244 
QLocale::UnitedArabEmirates245 
QLocale::UnitedKingdom246 
QLocale::UnitedStates248 
QLocale::UnitedStatesOutlyingIslands247 
QLocale::UnitedStatesMinorOutlyingIslandsUnitedStatesOutlyingIslands 
QLocale::UnitedStatesVirginIslands249 
QLocale::Uruguay250 
QLocale::Uzbekistan251 
QLocale::Vanuatu252 
QLocale::VaticanCity253 
QLocale::VaticanCityStateVaticanCity 
QLocale::Venezuela254 
QLocale::Vietnam255 
QLocale::WallisAndFutuna256 
QLocale::WallisAndFutunaIslandsWallisAndFutuna 
QLocale::WesternSahara257 
QLocale::World (since Qt 5.12)258 
QLocale::Yemen259 
QLocale::Zambia260 
QLocale::Zimbabwe261 

Note: Use the Territory alias for this enumeration where possible. The Country enum shall be renamed to Territory at a later release.

See also territory(), territoryToString(), codeToTerritory(), and territoryToCode().

enum QLocale::CurrencySymbolFormat

Specifies the format of the currency symbol.

ConstantValueDescription
QLocale::CurrencyIsoCode0a ISO-4217 code of the currency.
QLocale::CurrencySymbol1a currency symbol.
QLocale::CurrencyDisplayName2a user readable name of the currency.

enum QLocale::DataSizeFormat
flags QLocale::DataSizeFormats

Specifies the format for representation of data quantities.

ConstantValueDescription
QLocale::DataSizeIecFormat0format using base 1024 and IEC prefixes: KiB, MiB, GiB, ...
QLocale::DataSizeTraditionalFormatDataSizeSIQuantifiersformat using base 1024 and SI prefixes: kB, MB, GB, ...
QLocale::DataSizeSIFormatDataSizeBase1000 | DataSizeSIQuantifiersformat using base 1000 and SI prefixes: kB, MB, GB, ...

The DataSizeFormats type is a typedef for QFlags<DataSizeFormat>. It stores an OR combination of DataSizeFormat values.

See also formattedDataSize().

enum QLocale::FloatingPointPrecisionOption

This enum defines a constant that can be given as precision to QString::number(), QByteArray::number(), and QLocale::toString() when converting floats or doubles, in order to express a variable number of digits as precision.

ConstantValueDescription
QLocale::FloatingPointShortest-128The conversion algorithm will try to find the shortest accurate representation for the given number. "Accurate" means that you get the exact same number back from an inverse conversion on the generated string representation. In particular, trailing zeros are omitted (from the mantissa, in exponent formats).

See also toString(), QString::number(), and QByteArray::number().

enum QLocale::FormatType

This enum describes the different formats that can be used when converting QDate, QTime, and QDateTime objects, as well as months and days, to strings specific to the locale.

ConstantValueDescription
QLocale::LongFormat0Longer format.
QLocale::ShortFormat1Shorter format.
QLocale::NarrowFormat2A special version for use when space is very limited.

Note: NarrowFormat might contain the same text for different months and days. It can even be an empty string if the locale doesn't support narrow names, so you should avoid using it for date formatting. Also, for the system locale this format is the same as ShortFormat.

See also dateFormat(), timeFormat(), dateTimeFormat(), monthName(), standaloneMonthName(), dayName(), standaloneDayName(), toDate(), toTime(), and toDateTime().

enum QLocale::Language

This enumerated type is used to specify a language.

ConstantValueDescription
QLocale::AnyLanguage0 
QLocale::C1A simplified English locale; see QLocale::c()
QLocale::Abkhazian2 
QLocale::AfanOromoObsolete, please use Oromo
QLocale::Afar3 
QLocale::Afrikaans4 
QLocale::Aghem5 
QLocale::Akan6 
QLocale::Akkadian (since Qt 5.1)7 
QLocale::Akoose (since Qt 5.3)8 
QLocale::Albanian9 
QLocale::AmericanSignLanguage (since Qt 5.7)10 
QLocale::Amharic11 
QLocale::AncientEgyptian (since Qt 5.1)12 
QLocale::AncientGreek (since Qt 5.1)13 
QLocale::Anii (since Qt 6.7)341 
QLocale::Arabic14 
QLocale::Aragonese (since Qt 5.1)15 
QLocale::Aramaic (since Qt 5.1)16 
QLocale::Armenian17 
QLocale::Assamese18 
QLocale::Asturian19 
QLocale::Asu20 
QLocale::Atsam21 
QLocale::Avaric22 
QLocale::Avestan23 
QLocale::Aymara24 
QLocale::Azerbaijani25 
QLocale::Bafia26 
QLocale::Balinese (since Qt 5.1)27 
QLocale::Baluchi (since Qt 6.6)337 
QLocale::Bambara28 
QLocale::Bamun (since Qt 5.1)29 
QLocale::Bangla (since Qt 6.0)30 
QLocale::Basaa31 
QLocale::Bashkir32 
QLocale::Basque33 
QLocale::BatakToba (since Qt 5.1)34 
QLocale::Belarusian35 
QLocale::Bemba36 
QLocale::Bena37 
QLocale::BengaliBanglaObsolete, please use Bangla
QLocale::Bhojpuri (since Qt 5.7)38 
QLocale::BhutaniDzongkhaObsolete, please use Dzongkha
QLocale::Bislama39 
QLocale::Blin40 
QLocale::Bodo41 
QLocale::Bosnian42 
QLocale::Breton43 
QLocale::Buginese (since Qt 5.1)44 
QLocale::Bulgarian45 
QLocale::Burmese46 
QLocale::ByelorussianBelarusianObsolete, please use Belarusian
QLocale::CambodianKhmerObsolete, please use Khmer
QLocale::Cantonese (since Qt 5.7)47 
QLocale::Catalan48 
QLocale::Cebuano (since Qt 5.14)49 
QLocale::CentralAtlasTamazight (since Qt 6.0)50 
QLocale::CentralKurdish (since Qt 5.5)51 
QLocale::CentralMoroccoTamazightCentralAtlasTamazightObsolete, please use CentralAtlasTamazight
QLocale::Chakma (since Qt 5.1)52 
QLocale::Chamorro53 
QLocale::Chechen54 
QLocale::Cherokee55 
QLocale::ChewaNyanjaObsolete, please use Nyanja
QLocale::Chickasaw (since Qt 5.14)56 
QLocale::Chiga57 
QLocale::Chinese58(Mandarin)
QLocale::Church59 
QLocale::Chuvash60 
QLocale::Colognian61 
QLocale::Coptic (since Qt 5.1)62 
QLocale::Cornish63 
QLocale::Corsican64 
QLocale::Cree65 
QLocale::Croatian66 
QLocale::Czech67 
QLocale::Danish68 
QLocale::Divehi69 
QLocale::Dogri (since Qt 5.1)70 
QLocale::Duala71 
QLocale::Dutch72 
QLocale::Dzongkha73 
QLocale::Embu74 
QLocale::English75 
QLocale::Erzya (since Qt 5.14)76 
QLocale::Esperanto77 
QLocale::Estonian78 
QLocale::Ewe79 
QLocale::Ewondo80 
QLocale::Faroese81 
QLocale::Fijian82 
QLocale::Filipino83 
QLocale::Finnish84 
QLocale::French85 
QLocale::FrisianWesternFrisiansame as WesternFrisian
QLocale::Friulian86 
QLocale::Fulah87 
QLocale::Ga89 
QLocale::Gaelic88 
QLocale::Galician90 
QLocale::Ganda91 
QLocale::Geez92 
QLocale::Georgian93 
QLocale::German94 
QLocale::Gothic (since Qt 5.1)95 
QLocale::Greek96 
QLocale::GreenlandicKalaallisutObsolete, please use Kalaallisut
QLocale::Guarani97 
QLocale::Gujarati98 
QLocale::Gusii99 
QLocale::Haitian100 
QLocale::Haryanvi (since Qt 6.5)330 
QLocale::Hausa101 
QLocale::Hawaiian102 
QLocale::Hebrew103 
QLocale::Herero104 
QLocale::Hindi105 
QLocale::HiriMotu106 
QLocale::Hungarian107 
QLocale::Icelandic108 
QLocale::Ido (since Qt 5.12)109 
QLocale::Igbo110 
QLocale::InariSami (since Qt 5.5)111 
QLocale::Indonesian112 
QLocale::Ingush (since Qt 5.1)113 
QLocale::Interlingua114 
QLocale::Interlingue115 
QLocale::Inuktitut116 
QLocale::InupiakInupiaqObsolete, please use Inupiaq
QLocale::Inupiaq (since Qt 6.0)117 
QLocale::Irish118 
QLocale::Italian119 
QLocale::Japanese120 
QLocale::Javanese121 
QLocale::Jju122 
QLocale::JolaFonyi123 
QLocale::Kabuverdianu124 
QLocale::Kabyle125 
QLocale::Kaingang (since Qt 6.3)328 
QLocale::Kako126 
QLocale::Kalaallisut (since Qt 6.0)127 
QLocale::Kalenjin128 
QLocale::Kamba129 
QLocale::Kangri (since Qt 6.7)342 
QLocale::Kannada130 
QLocale::Kanuri131 
QLocale::Kashmiri132 
QLocale::Kazakh133 
QLocale::Kenyang (since Qt 5.5)134 
QLocale::Khmer135 
QLocale::Kiche (since Qt 5.5)136 
QLocale::Kikuyu137 
QLocale::Kinyarwanda138 
QLocale::KirghizKyrgyzObsolete, please use Kyrgyz
QLocale::Komi139 
QLocale::Kongo140 
QLocale::Konkani141 
QLocale::Korean142 
QLocale::Koro143 
QLocale::KoyraboroSenni144 
QLocale::KoyraChiini145 
QLocale::Kpelle146 
QLocale::Kuanyama (since Qt 6.0)147 
QLocale::Kurdish148 
QLocale::KurundiRundiObsolete, please use Rundi
QLocale::Kuvi (since Qt 6.8)344 
QLocale::KwanyamaKuanyamaObsolete, please use Kuanyama
QLocale::Kwasio149 
QLocale::Kyrgyz (since Qt 6.0)150 
QLocale::Lakota (since Qt 5.3)151 
QLocale::Langi152 
QLocale::Lao153 
QLocale::Latin154 
QLocale::Latvian155 
QLocale::Lezghian (since Qt 5.5)156 
QLocale::Limburgish157 
QLocale::Lingala158 
QLocale::Ligurian (since Qt 6.6)338 
QLocale::LiteraryChinese (since Qt 5.7)159 
QLocale::Lithuanian160 
QLocale::Lojban (since Qt 5.12)161 
QLocale::LowerSorbian (since Qt 5.5)162 
QLocale::LowGerman163 
QLocale::LubaKatanga164 
QLocale::LuleSami (since Qt 5.5)165 
QLocale::Luo166 
QLocale::Luxembourgish167 
QLocale::Luyia168 
QLocale::Macedonian169 
QLocale::Machame170 
QLocale::Maithili (since Qt 5.5)171 
QLocale::MakhuwaMeetto172 
QLocale::Makonde173 
QLocale::Malagasy174 
QLocale::Malay176 
QLocale::Malayalam175 
QLocale::Maltese177 
QLocale::Mandingo (since Qt 5.1)178 
QLocale::Manipuri (since Qt 5.1)179 
QLocale::Manx180 
QLocale::Maori181 
QLocale::Mapuche (since Qt 5.5)182 
QLocale::Marathi183 
QLocale::Marshallese184 
QLocale::Masai185 
QLocale::Mazanderani (since Qt 5.7)186 
QLocale::Mende (since Qt 5.5)187 
QLocale::Meru188 
QLocale::Meta189 
QLocale::Mohawk (since Qt 5.5)190 
QLocale::Moksha (since Qt 6.5)333 
QLocale::Mongolian191 
QLocale::Morisyen192 
QLocale::Mundang193 
QLocale::Muscogee (since Qt 5.14)194 
QLocale::Nama195 
QLocale::NauruLanguage196 
QLocale::NavahoNavajoObsolete, please use Navajo
QLocale::Navajo (since Qt 6.0)197 
QLocale::Ndonga198 
QLocale::Nepali199 
QLocale::Newari (since Qt 5.7)200 
QLocale::Ngiemboon201 
QLocale::Nheengatu (since Qt 6.3)329 
QLocale::NigerianPidgin (since Qt 6.0)203 
QLocale::Ngomba202 
QLocale::Nko (since Qt 5.5)204 
QLocale::NorthernFrisian (since Qt 6.5)331 
QLocale::NorthernLuri (since Qt 5.7)205 
QLocale::NorthernSami206 
QLocale::NorthernSotho207 
QLocale::NorthNdebele208 
QLocale::NorwegianBokmal209 
QLocale::NorwegianNynorsk210 
QLocale::Nuer211 
QLocale::Nyanja212 
QLocale::Nyankole213 
QLocale::Obolo (since Qt 6.5)336 
QLocale::Occitan214 
QLocale::Odia (since Qt 6.0)215 
QLocale::Ojibwa216 
QLocale::OldIrish (since Qt 5.1)217 
QLocale::OldNorse (since Qt 5.1)218 
QLocale::OldPersian (since Qt 5.1)219 
QLocale::OriyaOdiaObsolete, please use Odia
QLocale::Oromo220 
QLocale::Osage (since Qt 5.7)221 
QLocale::Ossetic222 
QLocale::Pahlavi (since Qt 5.1)223 
QLocale::Palauan (since Qt 5.7)224 
QLocale::Pali225 
QLocale::Papiamento (since Qt 5.7)226 
QLocale::Pashto227 
QLocale::Persian228 
QLocale::Phoenician (since Qt 5.1)229 
QLocale::Pijin (since Qt 6.5)335 
QLocale::Polish230 
QLocale::Portuguese231 
QLocale::Prussian (since Qt 5.5)232 
QLocale::Punjabi233 
QLocale::Quechua234 
QLocale::Rajasthani (since Qt 6.5)332 
QLocale::RhaetoRomanceRomanshObsolete, please use Romansh
QLocale::Rohingya (since Qt 6.6)339 
QLocale::Romanian235 
QLocale::Romansh236 
QLocale::Rombo237 
QLocale::Rundi238 
QLocale::Russian239 
QLocale::Rwa240 
QLocale::Saho241 
QLocale::Sakha242 
QLocale::Samburu243 
QLocale::Samoan244 
QLocale::Sango245 
QLocale::Sangu246 
QLocale::Sanskrit247 
QLocale::Santali (since Qt 5.1)248 
QLocale::Sardinian249 
QLocale::Saurashtra (since Qt 5.1)250 
QLocale::Sena251 
QLocale::Serbian252 
QLocale::Shambala253 
QLocale::Shona254 
QLocale::SichuanYi255 
QLocale::Sicilian (since Qt 5.12)256 
QLocale::Sidamo257 
QLocale::Silesian (since Qt 5.14)258 
QLocale::Sindhi259 
QLocale::Sinhala260 
QLocale::SkoltSami (since Qt 5.5)261 
QLocale::Slovak262 
QLocale::Slovenian263 
QLocale::Soga264 
QLocale::Somali265 
QLocale::SouthernKurdish (since Qt 5.12)266 
QLocale::SouthernSami (since Qt 5.5)267 
QLocale::SouthernSotho268 
QLocale::SouthNdebele269 
QLocale::Spanish270 
QLocale::StandardMoroccanTamazight (since Qt 5.3)271 
QLocale::Sundanese272 
QLocale::Swahili273 
QLocale::Swati274 
QLocale::Swedish275 
QLocale::SwissGerman276 
QLocale::Syriac277 
QLocale::Tachelhit278 
QLocale::Tahitian279 
QLocale::TaiDam (since Qt 5.1)280 
QLocale::Taita281 
QLocale::Tajik282 
QLocale::Tamil283 
QLocale::Taroko284 
QLocale::Tasawaq285 
QLocale::Tatar286 
QLocale::Telugu287 
QLocale::Teso288 
QLocale::Thai289 
QLocale::Tibetan290 
QLocale::Tigre291 
QLocale::Tigrinya292 
QLocale::TokelauLanguage (since Qt 5.7)293 
QLocale::TokiPona (since Qt 6.5)334 
QLocale::TokPisin (since Qt 5.7)294 
QLocale::Tongan295 
QLocale::Torwali (since Qt 6.6)340 
QLocale::Tsonga296 
QLocale::Tswana297 
QLocale::Turkish298 
QLocale::Turkmen299 
QLocale::TuvaluLanguage (since Qt 5.7)300 
QLocale::Tyap301 
QLocale::Ugaritic (since Qt 5.1)302 
QLocale::UighurUyghurObsolete, please use Uyghur
QLocale::UigurUyghurObsolete, please use Uyghur
QLocale::Ukrainian303 
QLocale::UpperSorbian (since Qt 5.5)304 
QLocale::Urdu305 
QLocale::Uyghur (since Qt 6.0)306 
QLocale::Uzbek307 
QLocale::Vai308 
QLocale::Venda309 
QLocale::Venetian (since Qt 6.7)343 
QLocale::Vietnamese310 
QLocale::Volapuk311 
QLocale::Vunjo312 
QLocale::WalamoWolayttaObsolete, please use Wolaytta
QLocale::Walloon313 
QLocale::Walser314 
QLocale::Warlpiri (since Qt 5.5)315 
QLocale::Welsh316 
QLocale::WesternBalochi (since Qt 5.12)317 
QLocale::WesternFrisian318same as Frisian
QLocale::Wolaytta (since Qt 6.0)319 
QLocale::Wolof320 
QLocale::Xhosa321 
QLocale::Yangben322 
QLocale::Yiddish323 
QLocale::Yoruba324 
QLocale::Zarma325 
QLocale::Zhuang326 
QLocale::Zulu327 

See also language() and languageToString().

enum QLocale::LanguageCodeType
flags QLocale::LanguageCodeTypes

This enum defines language code types that can be used to restrict set of language codes considered by codeToLanguage and languageToCode.

ConstantValueDescription
QLocale::ISO639Part11 << 0ISO 639 Part 1 Alpha 2 code.
QLocale::ISO639Part2B1 << 1ISO 639 Part 2 bibliographic Alpha 3 code.
QLocale::ISO639Part2T1 << 2ISO 639 Part 2 terminological Alpha 3 code.
QLocale::ISO639Part31 << 3ISO 639 Part 3 Alpha 3 code.
QLocale::LegacyLanguageCode1 << 15Codes that are not part of the above set, but that were supported by Qt in the past. This value can only be used by codeToLanguage(). It is ignored when passed to languageToCode().
QLocale::ISO639Part2ISO639Part2B | ISO639Part2TAny ISO 639 Part 2 code.
QLocale::ISO639Alpha2ISO639Part1Any ISO-639 2-letter code.
QLocale::ISO639Alpha3ISO639Part2 | ISO639Part3Any ISO-639 3-letter code.
QLocale::ISO639ISO639Alpha2 | ISO639Alpha3Any ISO 639 code.
QLocale::AnyLanguageCode-1Specifies that any code can be used.

The LanguageCodeTypes type is a typedef for QFlags<LanguageCodeType>. It stores an OR combination of LanguageCodeType values.

enum QLocale::MeasurementSystem

This enum defines which units are used for measurement.

ConstantValueDescription
QLocale::MetricSystem0This value indicates metric units, such as meters, centimeters and millimeters.
QLocale::ImperialUSSystem1This value indicates imperial units, such as inches and miles as they are used in the United States.
QLocale::ImperialUKSystem2This value indicates imperial units, such as inches and miles as they are used in the United Kingdom.
QLocale::ImperialSystemImperialUSSystemProvided for compatibility. Same as ImperialUSSystem

enum QLocale::NumberOption
flags QLocale::NumberOptions

This enum defines a set of options for number-to-string and string-to-number conversions. They can be retrieved with numberOptions() and set with setNumberOptions().

ConstantValueDescription
QLocale::DefaultNumberOptions0x0This option represents the default behavior, with group separators, with one leading zero in single digit exponents, and without trailing zeroes after the decimal dot.
QLocale::OmitGroupSeparator0x01If this option is set, the number-to-string functions will not insert group separators in their return values. The default is to insert group separators.
QLocale::RejectGroupSeparator0x02If this option is set, the string-to-number functions will fail if they encounter group separators in their input. The default is to accept numbers containing correctly placed group separators.
QLocale::OmitLeadingZeroInExponent0x04If this option is set, the number-to-string functions will not pad exponents with zeroes when printing floating point numbers in scientific notation. The default is to add one leading zero to single digit exponents.
QLocale::RejectLeadingZeroInExponent0x08If this option is set, the string-to-number functions will fail if they encounter an exponent padded with zeroes when parsing a floating point number in scientific notation. The default is to accept such padding.
QLocale::IncludeTrailingZeroesAfterDot0x10If this option is set, the number-to-string functions will pad numbers with zeroes to the requested precision in "g" or "most concise" mode, even if the number of significant digits is lower than the requested precision. The default is to omit trailing zeroes.
QLocale::RejectTrailingZeroesAfterDot0x20If this option is set, the string-to-number functions will fail if they encounter trailing zeroes after the decimal dot when parsing a number in scientific or decimal representation. The default is to accept trailing zeroes.

The NumberOptions type is a typedef for QFlags<NumberOption>. It stores an OR combination of NumberOption values.

See also setNumberOptions(), numberOptions(), and FloatingPointPrecisionOption.

enum QLocale::QuotationStyle

This enum defines a set of possible styles for locale specific quotation.

ConstantValueDescription
QLocale::StandardQuotation0If this option is set, the standard quotation marks will be used to quote strings.
QLocale::AlternateQuotation1If this option is set, the alternate quotation marks will be used to quote strings.

See also quoteString().

enum QLocale::Script

This enumerated type is used to specify a script.

ConstantValueDescription
QLocale::AnyScript0 
QLocale::AdlamScript (since Qt 5.7)1 
QLocale::AhomScript (since Qt 5.7)2 
QLocale::AnatolianHieroglyphsScript (since Qt 5.7)3 
QLocale::ArabicScript4 
QLocale::ArmenianScript5 
QLocale::AvestanScript (since Qt 5.1)6 
QLocale::BalineseScript (since Qt 5.1)7 
QLocale::BamumScript (since Qt 5.1)8 
QLocale::BanglaScript (since Qt 6.0)9 
QLocale::BassaVahScript (since Qt 5.5)10 
QLocale::BatakScript (since Qt 5.1)11 
QLocale::BengaliScriptBanglaScriptObsolete, please use BanglaScript
QLocale::BhaiksukiScript (since Qt 5.7)12 
QLocale::BopomofoScript (since Qt 5.1)13 
QLocale::BrahmiScript (since Qt 5.1)14 
QLocale::BrailleScript (since Qt 5.1)15 
QLocale::BugineseScript (since Qt 5.1)16 
QLocale::BuhidScript (since Qt 5.1)17 
QLocale::CanadianAboriginalScript (since Qt 5.1)18 
QLocale::CarianScript (since Qt 5.1)19 
QLocale::CaucasianAlbanianScript (since Qt 5.5)20 
QLocale::ChakmaScript (since Qt 5.1)21 
QLocale::ChamScript (since Qt 5.1)22 
QLocale::CherokeeScript23 
QLocale::CopticScript (since Qt 5.1)24 
QLocale::CuneiformScript (since Qt 5.1)25 
QLocale::CypriotScript (since Qt 5.1)26 
QLocale::CyrillicScript27 
QLocale::DeseretScript (since Qt 5.1)28 
QLocale::DevanagariScript29 
QLocale::DuployanScript (since Qt 5.5)30 
QLocale::EgyptianHieroglyphsScript (since Qt 5.1)31 
QLocale::ElbasanScript (since Qt 5.5)32 
QLocale::EthiopicScript33 
QLocale::FraserScript (since Qt 5.1)34 
QLocale::GeorgianScript35 
QLocale::GlagoliticScript (since Qt 5.1)36 
QLocale::GothicScript (since Qt 5.1)37 
QLocale::GranthaScript (since Qt 5.5)38 
QLocale::GreekScript39 
QLocale::GujaratiScript40 
QLocale::GurmukhiScript41 
QLocale::HangulScript (since Qt 5.1)42 
QLocale::HanifiScript (since Qt 6.6)142 
QLocale::HanScript (since Qt 5.1)43 
QLocale::HanunooScript (since Qt 5.1)44 
QLocale::HanWithBopomofoScript (since Qt 5.7)45 
QLocale::HatranScript (since Qt 5.7)46 
QLocale::HebrewScript47 
QLocale::HiraganaScript (since Qt 5.1)48 
QLocale::ImperialAramaicScript (since Qt 5.1)49 
QLocale::InscriptionalPahlaviScript (since Qt 5.1)50 
QLocale::InscriptionalParthianScript (since Qt 5.1)51 
QLocale::JamoScript (since Qt 5.7)52 
QLocale::JapaneseScript53 
QLocale::JavaneseScript (since Qt 5.1)54 
QLocale::KaithiScript (since Qt 5.1)55 
QLocale::KannadaScript56 
QLocale::KatakanaScript (since Qt 5.1)57 
QLocale::KayahLiScript (since Qt 5.1)58 
QLocale::KharoshthiScript (since Qt 5.1)59 
QLocale::KhmerScript (since Qt 5.1)60 
QLocale::KhojkiScript (since Qt 5.5)61 
QLocale::KhudawadiScript (since Qt 5.5)62 
QLocale::KoreanScript63 
QLocale::LannaScript (since Qt 5.1)64 
QLocale::LaoScript65 
QLocale::LatinScript66 
QLocale::LepchaScript (since Qt 5.1)67 
QLocale::LimbuScript (since Qt 5.1)68 
QLocale::LinearAScript (since Qt 5.5)69 
QLocale::LinearBScript (since Qt 5.1)70 
QLocale::LycianScript (since Qt 5.1)71 
QLocale::LydianScript (since Qt 5.1)72 
QLocale::MahajaniScript (since Qt 5.5)73 
QLocale::MalayalamScript74 
QLocale::MandaeanScript (since Qt 5.1)75 
QLocale::ManichaeanScript (since Qt 5.5)76 
QLocale::MarchenScript (since Qt 5.7)77 
QLocale::MeiteiMayekScript (since Qt 5.1)78 
QLocale::MendeScript (since Qt 6.0)79 
QLocale::MendeKikakuiScriptMendeScriptObsolete, please use MendeScript
QLocale::MeroiticCursiveScript (since Qt 5.1)80 
QLocale::MeroiticScript (since Qt 5.1)81 
QLocale::ModiScript (since Qt 5.5)82 
QLocale::MongolianScript83 
QLocale::MroScript (since Qt 5.5)84 
QLocale::MultaniScript (since Qt 5.7)85 
QLocale::MyanmarScript86 
QLocale::NabataeanScript (since Qt 5.5)87 
QLocale::NewaScript (since Qt 5.7)88 
QLocale::NewTaiLueScript (since Qt 5.1)89 
QLocale::NkoScript (since Qt 5.1)90 
QLocale::OghamScript (since Qt 5.1)92 
QLocale::OlChikiScript (since Qt 5.1)93 
QLocale::OldHungarianScript (since Qt 5.7)94 
QLocale::OldItalicScript (since Qt 5.1)95 
QLocale::OldNorthArabianScript (since Qt 5.5)96 
QLocale::OldPermicScript (since Qt 5.5)97 
QLocale::OldPersianScript (since Qt 5.1)98 
QLocale::OldSouthArabianScript (since Qt 5.1)99 
QLocale::OdiaScript (since Qt 6.0)91 
QLocale::OriyaScriptOdiaScriptObsolete, please use OdiaScript
QLocale::OrkhonScript (since Qt 5.1)100 
QLocale::OsageScript (since Qt 5.7)101 
QLocale::OsmanyaScript (since Qt 5.1)102 
QLocale::PahawhHmongScript (since Qt 5.5)103 
QLocale::PalmyreneScript (since Qt 5.5)104 
QLocale::PauCinHauScript (since Qt 5.5)105 
QLocale::PhagsPaScript (since Qt 5.1)106 
QLocale::PhoenicianScript (since Qt 5.1)107 
QLocale::PollardPhoneticScript (since Qt 5.1)108 
QLocale::PsalterPahlaviScript (since Qt 5.5)109 
QLocale::RejangScript (since Qt 5.1)110 
QLocale::RunicScript (since Qt 5.1)111 
QLocale::SamaritanScript (since Qt 5.1)112 
QLocale::SaurashtraScript (since Qt 5.1)113 
QLocale::SharadaScript (since Qt 5.1)114 
QLocale::ShavianScript (since Qt 5.1)115 
QLocale::SiddhamScript (since Qt 5.5)116 
QLocale::SignWritingScript (since Qt 5.7)117 
QLocale::SimplifiedChineseScriptSimplifiedHanScriptsame as SimplifiedHanScript
QLocale::SimplifiedHanScript118same as SimplifiedChineseScript
QLocale::SinhalaScript119 
QLocale::SoraSompengScript (since Qt 5.1)120 
QLocale::SundaneseScript (since Qt 5.1)121 
QLocale::SylotiNagriScript (since Qt 5.1)122 
QLocale::SyriacScript123 
QLocale::TagalogScript (since Qt 5.1)124 
QLocale::TagbanwaScript (since Qt 5.1)125 
QLocale::TaiLeScript (since Qt 5.1)126 
QLocale::TaiVietScript (since Qt 5.1)127 
QLocale::TakriScript (since Qt 5.1)128 
QLocale::TamilScript129 
QLocale::TangutScript (since Qt 5.7)130 
QLocale::TeluguScript131 
QLocale::ThaanaScript132 
QLocale::ThaiScript133 
QLocale::TibetanScript134 
QLocale::TifinaghScript135 
QLocale::TirhutaScript (since Qt 5.5)136 
QLocale::TraditionalChineseScriptTraditionalHanScriptsame as TraditionalHanScript
QLocale::TraditionalHanScript137same as TraditionalChineseScript
QLocale::UgariticScript (since Qt 5.1)138 
QLocale::VaiScript139 
QLocale::VarangKshitiScript (since Qt 5.5)140 
QLocale::YiScript141 

See also script(), scriptToString(), and languageToString().

[since 6.7] enum class QLocale::TagSeparator

Indicate how to combine the parts that make up a locale identifier.

A locale identifier may be made up of several tags, indicating language, script and territory (plus, potentially, other details), joined together to form the identifier. Various standards and conventional forms use either a dash (the Unicode HYPHEN-MINUS, U+002D) or an underscore (LOW LINE, U+005F). Different clients of QLocale may thus need one or the other.

ConstantValueDescription
QLocale::TagSeparator::Dash'-'Use '-', the dash or hyphen character.
QLocale::TagSeparator::Underscore'_'Use '_', the underscore character.

Note: Although dash and underscore are the only separators used in public standards (as at 2023), it is possible to cast any ASCII character to this type if a non-standard ASCII separator is needed. Casting a non-ASCII character (with decimal value above 127) is not supported: such values are reserved for future use as enum members if some public standard ever uses a non-ASCII separator. It is, of course, possible to use QString::replace() to replace the separator used by a function taking a parameter of this type with an arbitrary Unicode character or string.

This enum was introduced in Qt 6.7.

[alias] QLocale::Territory

This enumeration type is an alias for Country, which shall be renamed to Territory at a future release.

See also territory() and territoryToString().

Member Function Documentation

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() and system().

[explicit, since 6.3] QLocale::QLocale(QStringView name)

Constructs a QLocale object with the specified name.

The name has the format "language[_script][_territory][.codeset][@modifier]" or "C", where:

  • language is a lowercase, two-letter, ISO 639 language code (some three-letter codes are also recognized),
  • script is a capitalized, four-letter, ISO 15924 script code,
  • territory is an uppercase, two-letter, ISO 3166 territory code (some numeric codes are also recognized), and
  • codeset and modifier are ignored.

The separator can be either underscore '_' (U+005F, "low line") or a dash '-' (U+002D, "hyphen-minus"). If QLocale has no data for the specified combination of language, script, and territory, then it uses the most suitable match it can find instead. If the string violates the locale format, or no suitable data can be found for the specified keys, the "C" locale is used instead.

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

This function was introduced in Qt 6.3.

See also bcp47Name() and Matching combinations of language, script and territory.

QLocale::QLocale(QLocale::Language language, QLocale::Territory territory)

Constructs a QLocale object for the specified language and territory.

If there is more than one script in use for this combination, a likely script will be selected. If QLocale has no data for the specified language, the default locale is used. If QLocale has no data for the specified combination of language and territory, an alternative territory may be used instead.

See also setDefault() and Matching combinations of language, script and territory.

QLocale::QLocale(QLocale::Language language, QLocale::Script script = AnyScript, QLocale::Territory territory = AnyTerritory)

Constructs a QLocale object for the specified language, script and territory.

If QLocale does not have data for the given combination, it will find data for as good a match as it can. It falls back on the default locale if

  • language is AnyLanguage and no language can be inferred from script and territory
  • QLocale has no data for the language, either given as language or inferred as above.

See also setDefault() and Matching combinations of language, script and territory.

[explicit] QLocale::QLocale(const QString &name)

This is an overloaded function.

[noexcept] QLocale::QLocale(const QLocale &other)

Constructs a QLocale object as a copy of other.

[noexcept] 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.

See also pmText().

QString QLocale::bcp47Name(QLocale::TagSeparator separator = TagSeparator::Dash) const

Returns the BCP47 field names joined with dashes.

This combines as many of language, script and territory (and possibly other BCP47 fields) for this locale as are needed to uniquely specify it. Note that fields may be omitted if the Unicode consortium's Likely Subtag Rules imply the omitted fields when given those retained. See name() for how to construct a string from individual fields, if some other format is needed.

Unlike uiLanguages(), the value returned by bcp47Name() represents the locale name of the QLocale data; this need not be the language the user-interface should be in.

This function tries to conform the locale name to the IETF Best Common Practice 47, defined by RFC 5646. Since Qt 6.7, it supports an optional separator parameter which can be used to override the BCP47-specified use of a hyphen to separate the tags. For use in IETF-defined protocols, however, the default, QLocale::TagSeparator::Dash, should be retained.

See also name(), language(), territory(), 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().

[static noexcept, since 6.3] QLocale::Language QLocale::codeToLanguage(QStringView languageCode, QLocale::LanguageCodeTypes codeTypes = AnyLanguageCode)

Returns the QLocale::Language enum corresponding to the two- or three-letter languageCode, as defined in the ISO 639 standards.

If specified, codeTypes selects which set of codes to consider for conversion. By default all codes known to Qt are considered. The codes are matched in the following order: ISO639Part1, ISO639Part2B, ISO639Part2T, ISO639Part3, LegacyLanguageCode.

If the code is invalid or not known QLocale::AnyLanguage is returned.

This function was introduced in Qt 6.3.

See also languageToCode(), codeToTerritory(), and codeToScript().

[static noexcept, since 6.1] QLocale::Script QLocale::codeToScript(QStringView scriptCode)

Returns the QLocale::Script enum corresponding to the four-letter script scriptCode, as defined in the ISO 15924 standard.

If the code is invalid or not known QLocale::AnyScript is returned.

This function was introduced in Qt 6.1.

See also scriptToCode(), codeToLanguage(), and codeToTerritory().

[static noexcept, since 6.2] QLocale::Territory QLocale::codeToTerritory(QStringView territoryCode)

Returns the QLocale::Territory enum corresponding to the two-letter or three-digit territoryCode, as defined in the ISO 3166 standard.

If the code is invalid or not known QLocale::AnyTerritory is returned.

This function was introduced in Qt 6.2.

See also territoryToCode(), codeToLanguage(), and codeToScript().

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.

See also QCollator.

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.

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

Returns a currency symbol according to the format.

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.

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.

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.

See also monthName() and standaloneDayName().

QString QLocale::decimalPoint() const

Returns the fractional part separator for this locale.

This is the token that separates the whole number part from the fracional part in the representation of a number which has a fractional part. This is commonly called the "decimal point character" - even though, in many locales, it is not a "point" (or similar dot). It is (since Qt 6.0) returned as a string in case some locale needs more than one UTF-16 code-point to represent its separator.

See also groupSeparator() and toString().

QString QLocale::exponential() const

Returns the exponent separator for this locale.

This is a token used to separate mantissa from exponent in some floating-point numeric representations. It is (since Qt 6.0) returned as a string because, in some locales, it is not a single character - for example, it may consist of a multiplication sign and a representation of the "ten to the power" operator.

See also toString(double, char, int).

Qt::DayOfWeek QLocale::firstDayOfWeek() const

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

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.

QString QLocale::groupSeparator() const

Returns the digit-grouping separator for this locale.

This is a token used to break up long sequences of digits, in the representation of a number, to make it easier to read. In some locales it may be empty, indicating that digits should not be broken up into groups in this way. In others it may be a spacing character. It is (since Qt 6.0) returned as a string in case some locale needs more than one UTF-16 code-point to represent its separator.

See also decimalPoint() and toString().

QLocale::Language QLocale::language() const

Returns the language of this locale.

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

[static, since 6.3] QString QLocale::languageToCode(QLocale::Language language, QLocale::LanguageCodeTypes codeTypes = AnyLanguageCode)

Returns the two- or three-letter language code for language, as defined in the ISO 639 standards.

If specified, codeTypes selects which set of codes to consider. The first code from the set that is defined for language is returned. Otherwise, all ISO-639 codes are considered. The codes are considered in the following order: ISO639Part1, ISO639Part2B, ISO639Part2T, ISO639Part3. LegacyLanguageCode is ignored by this function.

Note: For QLocale::C the function returns "C". For QLocale::AnyLanguage an empty string is returned. If the language has no code in any selected code set, an empty string is returned.

This function was introduced in Qt 6.3.

See also codeToLanguage(), language(), name(), bcp47Name(), territoryToCode(), and scriptToCode().

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

Returns a QString containing the name of language.

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

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

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

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

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

QLocale::MeasurementSystem QLocale::measurementSystem() const

Returns the measurement system for the locale.

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.

See also dayName() and standaloneMonthName().

QString QLocale::name(QLocale::TagSeparator separator = TagSeparator::Underscore) const

The short name of this locale.

Returns the language and territory of this locale as a string of the form "language_territory", where language is a lowercase, two-letter ISO 639 language code, and territory is an uppercase, two- or three-letter ISO 3166 territory code. If the locale has no specified territory, only the language name is returned. Since Qt 6.7 an optional separator parameter can be supplied to override the default underscore character separating the two tags.

Even if the 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, or construct the string you want to identify a locale by from those returned by passing its language() to languageToCode() and similar for the script and territory.

See also QLocale(), language(), script(), territory(), bcp47Name(), and uiLanguages().

QString QLocale::nativeLanguageName() const

Returns a native name of the language for the locale. For example "Schweizer Hochdeutsch" for the Swiss-German locale.

See also nativeTerritoryName() and languageToString().

[since 6.2] QString QLocale::nativeTerritoryName() const

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

This function was introduced in Qt 6.2.

See also nativeLanguageName() and territoryToString().

QString QLocale::negativeSign() const

Returns the negative sign indicator of this locale.

This is a token presumed to be used as a prefix to a number to indicate that it is negative. It is (since Qt 6.0) returned as a string because, in some locales, it is not a single character - for example, because it includes a text-direction-control character.

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.

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

QString QLocale::percent() const

Returns the percent marker of this locale.

This is a token presumed to be appended to a number to indicate a percentage. It is (since Qt 6.0) returned as a string because, in some locales, it is not a single character - for example, because it includes a text-direction-control character.

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.

See also amText().

QString QLocale::positiveSign() const

Returns the positive sign indicator of this locale.

This is a token presumed to be used as a prefix to a number to indicate that it is positive. It is (since Qt 6.0) returned as a string because, in some locales, it is not a single character - for example, because it includes a text-direction-control character.

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.

[since 6.0] QString QLocale::quoteString(QStringView str, QLocale::QuotationStyle style = StandardQuotation) const

This is an overloaded function.

This function was introduced in Qt 6.0.

QLocale::Script QLocale::script() const

Returns the script of this locale.

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

[static, since 6.1] QString QLocale::scriptToCode(QLocale::Script script)

Returns the four-letter script code for script, as defined in the ISO 15924 standard.

Note: For QLocale::AnyScript an empty string is returned.

This function was introduced in Qt 6.1.

See also script(), name(), bcp47Name(), languageToCode(), and territoryToCode().

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

Returns a QString containing the name of script.

See also languageToString(), territoryToString(), 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.

See also numberOptions() and FloatingPointPrecisionOption.

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().

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().

See also monthName() and standaloneDayName().

[noexcept] void QLocale::swap(QLocale &other)

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

[static] QLocale QLocale::system()

Returns a QLocale object initialized to the system locale.

The system locale may use system-specific sources for locale data, where available, otherwise falling back on QLocale's built-in database entry for the language, script and territory the system reports.

For example, 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().

[since 6.2] QLocale::Territory QLocale::territory() const

Returns the territory of this locale.

This function was introduced in Qt 6.2.

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

[static, since 6.2] QString QLocale::territoryToCode(QLocale::Territory territory)

Returns the two-letter territory code for territory, as defined in the ISO 3166 standard.

Note: For QLocale::AnyTerritory an empty string is returned.

This function was introduced in Qt 6.2.

See also codeToTerritory(), territory(), name(), bcp47Name(), languageToCode(), and scriptToCode().

[static, since 6.2] QString QLocale::territoryToString(QLocale::Territory territory)

Returns a QString containing the name of territory.

This function was introduced in Qt 6.2.

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

Qt::LayoutDirection QLocale::textDirection() const

Returns the text direction of the language.

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.

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.

See also currencySymbol().

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

QString QLocale::toCurrencyString(double value, const QString &symbol = QString(), int precision = -1) 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.

See also currencySymbol().

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

This function overloads toCurrencyString().

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

Reads string as a date in a locale-specific format.

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

Some locales use, particularly for ShortFormat, only the last two digits of the year. In such a case, the 100 years starting at baseYear are the candidates first considered. Prior to 6.7 there was no baseYear parameter and 1900 was always used. This is the default for baseYear, selecting a year from then to 1999. In some cases, other fields may lead to the next or previous century being selected, to get a result consistent with all fields given. See QDate::fromString() for details.

Note: Month and day names, where used, must be given in the locale's language.

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

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

QDate QLocale::toDate(const QString &string, const QString &format, int baseYear = DefaultTwoDigitBaseYear) const

Reads string as a date in the given format.

Parses string and returns the date it represents. See QDate::fromString() for the interpretation of format.

When format only specifies the last two digits of a year, the 100 years starting at baseYear are the candidates first considered. Prior to 6.7 there was no baseYear parameter and 1900 was always used. This is the default for baseYear, selecting a year from then to 1999. In some cases, other fields may lead to the next or previous century being selected, to get a result consistent with all fields given. See QDate::fromString() for details.

Note: Month and day names, where used, must be given in the locale's language.

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

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

QDate QLocale::toDate(const QString &string, QLocale::FormatType format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const

This is an overloaded function.

QDate QLocale::toDate(const QString &string, const QString &format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const

This is an overloaded function.

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

Reads string as a date-time in a locale-specific format.

Parses string and returns the date-time it represents. The format of the date string is chosen according to the format parameter (see dateFormat()).

Some locales use, particularly for ShortFormat, only the last two digits of the year. In such a case, the 100 years starting at baseYear are the candidates first considered. Prior to 6.7 there was no baseYear parameter and 1900 was always used. This is the default for baseYear, selecting a year from then to 1999. In some cases, other fields may lead to the next or previous century being selected, to get a result consistent with all fields given. See QDate::fromString() for details.

Note: Month and day names, where used, must be given in the locale's language. Any am/pm indicators used must match amText() or pmText(), ignoring case.

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

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

QDateTime QLocale::toDateTime(const QString &string, const QString &format, int baseYear = DefaultTwoDigitBaseYear) const

Reads string as a date-time in the given format.

Parses string and returns the date-time it represents. See QDateTime::fromString() for the interpretation of format.

When format only specifies the last two digits of a year, the 100 years starting at baseYear are the candidates first considered. Prior to 6.7 there was no baseYear parameter and 1900 was always used. This is the default for baseYear, selecting a year from then to 1999. In some cases, other fields may lead to the next or previous century being selected, to get a result consistent with all fields given. See QDate::fromString() for details.

Note: Month and day names, where used, must be given in the locale's language. Any am/pm indicators used must match amText() or pmText(), ignoring case.

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.

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

QDateTime QLocale::toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const

This is an overloaded function.

QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCalendar cal, int baseYear = DefaultTwoDigitBaseYear) const

This is an overloaded function.

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.

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.

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

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.

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().

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.

See also toDouble(), 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 ignores leading and trailing whitespace.

See also toDouble(), toInt(), 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.

See also toUInt() 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().

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.

See also toInt(), toULong(), toDouble(), 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.

See also toInt(), toULong(), 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.

See also toInt(), toULongLong(), 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().

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.

See also QString::toLower().

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.

See also toUShort() and toString().

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().

QString QLocale::toString(qlonglong i) const

Returns a localized string representation of i.

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

QString QLocale::toString(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(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(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.

See also QTime::toString().

QString QLocale::toString(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.

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

QString QLocale::toString(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.

QString QLocale::toString(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.

See also QDate::toString().

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.

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.

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

QString QLocale::toString(int i) const

This is an overloaded function.

See also toInt().

QString QLocale::toString(long i) const

This is an overloaded function.

See also toLong().

QString QLocale::toString(qulonglong i) const

This is an overloaded function.

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

QString QLocale::toString(short i) const

This is an overloaded function.

See also toShort().

QString QLocale::toString(uint i) const

This is an overloaded function.

See also toUInt().

QString QLocale::toString(ulong i) const

This is an overloaded function.

See also toULong().

QString QLocale::toString(ushort i) const

This is an overloaded function.

See also toUShort().

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

Returns a string representing the floating-point number f.

The form of the representation is controlled by the format and precision parameters.

The format defaults to 'g'. It can be any of the following:

FormatMeaningMeaning of precision
'e'format as [-]9.9e[+|-]999number of digits after the decimal point
'E'format as [-]9.9E[+|-]999"
'f'format as [-]9.9"
'F'same as 'f' except for INF and NAN (see below)"
'g'use 'e' or 'f' format, whichever is more concisemaximum number of significant digits (trailing zeroes are omitted)
'G'use 'E' or 'F' format, whichever is more concise"

The special precision value QLocale::FloatingPointShortest selects the shortest representation that, when read as a number, gets back the original floating-point value. Aside from that, any negative precision is ignored in favor of the default, 6.

For the 'e', 'f' and 'g' formats, positive infinity is represented as "inf", negative infinity as "-inf" and floating-point NaN (not-a-number) values are represented as "nan". For the 'E', 'F' and 'G' formats, "INF" and "NAN" are used instead. This does not vary with locale.

See also toDouble(), numberOptions(), exponential(), decimalPoint(), zeroDigit(), positiveSign(), percent(), toCurrencyString(), formattedDataSize(), and QLocale::FloatingPointPrecisionOption.

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

This is an overloaded function.

Returns a string representing the floating-point number f.

The format and precision have the same meanings as described in toString(double, char, int).

See also toFloat(), toDouble(), numberOptions(), exponential(), decimalPoint(), zeroDigit(), positiveSign(), percent(), toCurrencyString(), formattedDataSize(), and QLocale::FloatingPointPrecisionOption.

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

Reads string as a time in a locale-specific format.

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

Note: Any am/pm indicators used must match amText() or pmText(), ignoring case.

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

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

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

Reads string as a time in the given format.

Parses string and returns the time it represents. See QTime::fromString() for the interpretation of format.

Note: Any am/pm indicators used must match amText() or pmText(), ignoring case.

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

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

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.

See also toInt() and toString().

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().

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.

See also toLong(), toInt(), toDouble(), 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.

See also toLong(), 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.

See also toLongLong(), 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().

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.

See also toShort() 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().

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.

See also QString::toUpper().

QStringList QLocale::uiLanguages(QLocale::TagSeparator separator = TagSeparator::Dash) const

List of locale names for use in selecting translations

Each entry in the returned list is the name of a locale suitable to the user's preferences for what to translate the UI into. Where a name in the list is composed of several tags, they are joined as indicated by separator. Prior to Qt 6.7 a dash was used as separator.

For example, using the default separator QLocale::TagSeparator::Dash, if the user has configured their system to use English as used in the USA, the list would be "en-Latn-US", "en-US", "en". The order of entries is the order in which to check for translations; earlier items in the list are to be preferred over later ones. If your translation files use underscores, rather than dashes, to separate locale tags, pass QLocale::TagSeparator::Underscore as separator.

The returned list may contain entries for more than one language. In particular, this happens for system locale when the user has configured the system to accept several languages for user-interface translations. In such a case, the order of entries for distinct languages is significant. For example, where a user has configured a primarily German system to also accept English and Chinese, in that order of preference, the returned list shall contain some entries for German, then some for English, and finally some for Chinese.

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

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.

QString QLocale::zeroDigit() const

Returns the zero digit character of this locale.

This is a single Unicode character but may be encoded as a surrogate pair, so is (since Qt 6.0) returned as a string. In most locales, other digits follow it in Unicode ordering - however, some number systems, notably those using U+3007 as zero, do not have contiguous digits. Use toString() to obtain suitable representations of numbers, rather than trying to construct them from this zero digit.

See also toString().

[noexcept] QLocale &QLocale::operator=(const QLocale &other)

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

Member Variable Documentation

[since 6.7] const int QLocale::DefaultTwoDigitBaseYear

This variable holds the default start year of the century within which a format taking a two-digit year will select. The value of the constant is 1900.

Some locales use, particularly for ShortFormat, only the last two digits of the year. Proir to 6.7 the year 1900 was always used as a base year for such cases. Now various QLocale and QDate functions have the overloads that allow callers to specify the base year, and this constant is used as its default value.

This documentation was introduced in Qt 6.7.

See also toDate(), toDateTime(), QDate::fromString(), and QDateTime::fromString().

Related Non-Members

[noexcept] size_t qHash(const QLocale &key, size_t seed = 0)

Returns the hash value for key, using seed to seed the calculation.

[noexcept] bool operator!=(const QLocale &lhs, const QLocale &rhs)

Returns true if the two QLocale objects, lhs and rhs, differ; otherwise returns false.

Note: The system locale is not equal to the QLocale object constructed from its language(), script() and territory(), even if the two agree in all data fields. Nor are two locales with different number options equal.

See also operator==() and setNumberOptions().

[noexcept] bool operator==(const QLocale &lhs, const QLocale &rhs)

Returns true if the two QLocale objects, lhs and rhs, are the same; otherwise returns false.

Note: The system locale is not equal to the QLocale object constructed from its language(), script() and territory(), even if the two agree in all data fields. Nor are two locales with different number options equal.

See also operator!=() and setNumberOptions().

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.