QLocale Class

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

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

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 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 }
Territory

Public Functions

QLocale(const QLocale &other)
QLocale(QLocale::Language language, QLocale::Script script = AnyScript, QLocale::Territory territory = AnyTerritory)
QLocale(QLocale::Language language, QLocale::Territory territory)
QLocale(const QString &name)
QLocale()
QLocale &operator=(const QLocale &other)
~QLocale()
QString amText() const
QString bcp47Name() 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() const
QString nativeLanguageName() const
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
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)
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(qulonglong value, const QString &symbol = QString()) const
QString toCurrencyString(short value, const QString &symbol = QString()) const
QString toCurrencyString(ushort value, const QString &symbol = QString()) const
QString toCurrencyString(int value, const QString &symbol = QString()) const
QString toCurrencyString(uint 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) const
QDate toDate(const QString &string, const QString &format) const
QDate toDate(const QString &string, QLocale::FormatType format, QCalendar cal) const
QDate toDate(const QString &string, const QString &format, QCalendar cal) const
QDateTime toDateTime(const QString &string, QLocale::FormatType format = LongFormat) const
QDateTime toDateTime(const QString &string, const QString &format) const
QDateTime toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal) const
QDateTime toDateTime(const QString &string, const QString &format, QCalendar cal) const
double toDouble(const QString &s, bool *ok = nullptr) const
double toDouble(QStringView s, bool *ok = nullptr) const
float toFloat(const QString &s, bool *ok = nullptr) const
float toFloat(QStringView s, bool *ok = nullptr) const
int toInt(const QString &s, bool *ok = nullptr) const
int toInt(QStringView s, bool *ok = nullptr) const
long toLong(const QString &s, bool *ok = nullptr) const
long toLong(QStringView s, bool *ok = nullptr) const
qlonglong toLongLong(const QString &s, bool *ok = nullptr) const
qlonglong toLongLong(QStringView s, bool *ok = nullptr) const
QString toLower(const QString &str) const
short toShort(const QString &s, bool *ok = nullptr) const
short toShort(QStringView s, bool *ok = nullptr) const
QString toString(qlonglong i) const
QString toString(qulonglong i) const
QString toString(long i) const
QString toString(ulong i) const
QString toString(short i) const
QString toString(ushort i) const
QString toString(int i) const
QString toString(uint i) const
QString toString(double f, char format = 'g', int precision = 6) const
QString toString(float f, char format = 'g', int precision = 6) const
QString toString(QDate date, const QString &format) const
QString toString(QTime time, const QString &format) const
QString toString(const QDateTime &dateTime, const QString &format) const
QString toString(QDate date, QStringView format) const
QString toString(QTime time, QStringView format) const
QString toString(const QDateTime &dateTime, QStringView format) const
QString toString(QDate date, QLocale::FormatType format = LongFormat) const
QString toString(QTime time, QLocale::FormatType format = LongFormat) const
QString toString(const QDateTime &dateTime, QLocale::FormatType format = LongFormat) const
QString toString(QDate date, QStringView format, QCalendar cal) const
QString toString(QDate date, QLocale::FormatType 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
QTime toTime(const QString &string, QLocale::FormatType format = LongFormat) const
QTime toTime(const QString &string, const QString &format) const
uint toUInt(const QString &s, bool *ok = nullptr) const
uint toUInt(QStringView s, bool *ok = nullptr) const
ulong toULong(const QString &s, bool *ok = nullptr) const
ulong toULong(QStringView s, bool *ok = nullptr) const
qulonglong toULongLong(const QString &s, bool *ok = nullptr) const
qulonglong toULongLong(QStringView s, bool *ok = nullptr) const
ushort toUShort(const QString &s, bool *ok = nullptr) const
ushort toUShort(QStringView s, bool *ok = nullptr) const
QString toUpper(const QString &str) const
QStringList uiLanguages() const
QList<Qt::DayOfWeek> weekdays() const
QString zeroDigit() const

Static Public Members

QLocale c()
QLocale::Language codeToLanguage(QStringView languageCode)
QLocale::Script codeToScript(QStringView scriptCode)
QLocale::Territory codeToTerritory(QStringView territoryCode)
QString languageToCode(QLocale::Language language)
QString languageToString(QLocale::Language language)
QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Territory territory)
QString scriptToCode(QLocale::Script script)
QString scriptToString(QLocale::Script script)
void setDefault(const QLocale &locale)
QLocale system()
QString territoryToCode(QLocale::Territory territory)
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::AnyTerritory0Since 6.2
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::BosniaAndHerzegovina29Since 6.0
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::Curacao62Since Qt 6.0
QLocale::CuraSaoCuracaoObsolete, use Curacao instead
QLocale::Cyprus63 
QLocale::Czechia64Since 6.0
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::EuropeanUnion79Since Qt 5.7
QLocale::Europe78Since Qt 5.12
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::Kosovo126Since Qt 5.2
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::NauruTerritory163Since 6.2
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::OutlyingOceania177Since Qt 5.7
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::TokelauTerritory234Since 6.2
QLocale::Tonga235 
QLocale::TrinidadAndTobago236 
QLocale::TristanDaCunha237 
QLocale::Tunisia238 
QLocale::Turkey239 
QLocale::Turkmenistan240 
QLocale::TurksAndCaicosIslands241 
QLocale::TuvaluCountryTuvaluTerritoryOsbolete alias for TuvaluTerritory
QLocale::TuvaluTerritory242Since 6.2
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::World258Since Qt 5.12
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.

[since 5.10] 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, ...

This enum was introduced or modified in Qt 5.10.

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

See also formattedDataSize().

[since 5.7] 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).

This enum was introduced or modified in Qt 5.7.

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::Akkadian7Since Qt 5.1
QLocale::Akoose8Since Qt 5.3
QLocale::Albanian9 
QLocale::AmericanSignLanguage10Since Qt 5.7
QLocale::Amharic11 
QLocale::AncientEgyptian12Since Qt 5.1
QLocale::AncientGreek13Since Qt 5.1
QLocale::Anii (since Qt 6.7)341 
QLocale::Arabic14 
QLocale::Aragonese15Since Qt 5.1
QLocale::Aramaic16Since Qt 5.1
QLocale::Armenian17 
QLocale::Assamese18 
QLocale::Asturian19 
QLocale::Asu20 
QLocale::Atsam21 
QLocale::Avaric22 
QLocale::Avestan23 
QLocale::Aymara24 
QLocale::Azerbaijani25 
QLocale::Bafia26 
QLocale::Balinese27Since Qt 5.1
QLocale::Baluchi (since Qt 6.6)337 
QLocale::Bambara28 
QLocale::Bamun29Since Qt 5.1
QLocale::Bangla30Since Qt 6.0
QLocale::Basaa31 
QLocale::Bashkir32 
QLocale::Basque33 
QLocale::BatakToba34Since Qt 5.1
QLocale::Belarusian35 
QLocale::Bemba36 
QLocale::Bena37 
QLocale::BengaliBanglaObsolete, please use Bangla
QLocale::Bhojpuri38Since Qt 5.7
QLocale::BhutaniDzongkhaObsolete, please use Dzongkha
QLocale::Bislama39 
QLocale::Blin40 
QLocale::Bodo41 
QLocale::Bosnian42 
QLocale::Breton43 
QLocale::Buginese44Since Qt 5.1
QLocale::Bulgarian45 
QLocale::Burmese46 
QLocale::ByelorussianBelarusianObsolete, please use Belarusian
QLocale::CambodianKhmerObsolete, please use Khmer
QLocale::Cantonese47Since Qt 5.7
QLocale::Catalan48 
QLocale::Cebuano49Since Qt 5.14
QLocale::CentralAtlasTamazight50Since Qt 6.0
QLocale::CentralKurdish51Since Qt 5.5
QLocale::CentralMoroccoTamazightCentralAtlasTamazightObsolete, please use CentralAtlasTamazight
QLocale::Chakma52Since Qt 5.1
QLocale::Chamorro53 
QLocale::Chechen54 
QLocale::Cherokee55 
QLocale::ChewaNyanjaObsolete, please use Nyanja
QLocale::Chickasaw56Since Qt 5.14
QLocale::Chiga57 
QLocale::Chinese58(Mandarin)
QLocale::Church59 
QLocale::Chuvash60 
QLocale::Colognian61 
QLocale::Coptic62Since Qt 5.1
QLocale::Cornish63 
QLocale::Corsican64 
QLocale::Cree65 
QLocale::Croatian66 
QLocale::Czech67 
QLocale::Danish68 
QLocale::Divehi69 
QLocale::Dogri70Since Qt 5.1
QLocale::Duala71 
QLocale::Dutch72 
QLocale::Dzongkha73 
QLocale::Embu74 
QLocale::English75 
QLocale::Erzya76Since Qt 5.14
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::Gothic95Since Qt 5.1
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::Ido109Since Qt 5.12
QLocale::Igbo110 
QLocale::InariSami111Since Qt 5.5
QLocale::Indonesian112 
QLocale::Ingush113Since Qt 5.1
QLocale::Interlingua114 
QLocale::Interlingue115 
QLocale::Inuktitut116 
QLocale::InupiakInupiaqObsolete, please use Inupiaq
QLocale::Inupiaq117Since 6.0
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::Kalaallisut127Since Qt 6.0
QLocale::Kalenjin128 
QLocale::Kamba129 
QLocale::Kangri (since Qt 6.7)342 
QLocale::Kannada130 
QLocale::Kanuri131 
QLocale::Kashmiri132 
QLocale::Kazakh133 
QLocale::Kenyang134Since Qt 5.5
QLocale::Khmer135 
QLocale::Kiche136Since Qt 5.5
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::Kuanyama147Since 6.0
QLocale::Kurdish148 
QLocale::KurundiRundiObsolete, please use Rundi
QLocale::Kuvi (since Qt 6.8)344 
QLocale::KwanyamaKuanyamaObsolete, please use Kuanyama
QLocale::Kwasio149 
QLocale::Kyrgyz150Since 6.0
QLocale::Lakota151Since Qt 5.3
QLocale::Langi152 
QLocale::Lao153 
QLocale::Latin154 
QLocale::Latvian155 
QLocale::Lezghian156Since Qt 5.5
QLocale::Limburgish157 
QLocale::Lingala158 
QLocale::Ligurian (since Qt 6.6)338 
QLocale::LiteraryChinese159Since Qt 5.7
QLocale::Lithuanian160 
QLocale::Lojban161Since Qt 5.12
QLocale::LowerSorbian162Since Qt 5.5
QLocale::LowGerman163 
QLocale::LubaKatanga164 
QLocale::LuleSami165Since Qt 5.5
QLocale::Luo166 
QLocale::Luxembourgish167 
QLocale::Luyia168 
QLocale::Macedonian169 
QLocale::Machame170 
QLocale::Maithili171Since Qt 5.5
QLocale::MakhuwaMeetto172 
QLocale::Makonde173 
QLocale::Malagasy174 
QLocale::Malay176 
QLocale::Malayalam175 
QLocale::Maltese177 
QLocale::Mandingo178Since Qt 5.1
QLocale::Manipuri179Since Qt 5.1
QLocale::Manx180 
QLocale::Maori181 
QLocale::Mapuche182Since Qt 5.5
QLocale::Marathi183 
QLocale::Marshallese184 
QLocale::Masai185 
QLocale::Mazanderani186Since Qt 5.7
QLocale::Mende187Since Qt 5.5
QLocale::Meru188 
QLocale::Meta189 
QLocale::Mohawk190Since Qt 5.5
QLocale::Moksha (since Qt 6.5)333 
QLocale::Mongolian191 
QLocale::Morisyen192 
QLocale::Mundang193 
QLocale::Muscogee194Since Qt 5.14
QLocale::Nama195 
QLocale::NauruLanguage196 
QLocale::NavahoNavajoObsolete, please use Navajo
QLocale::Navajo197Since 6.0
QLocale::Ndonga198 
QLocale::Nepali199 
QLocale::Newari200Since Qt 5.7
QLocale::Ngiemboon201 
QLocale::Nheengatu (since Qt 6.3)329 
QLocale::NigerianPidgin203Since Qt 6.0
QLocale::Ngomba202 
QLocale::Nko204Since Qt 5.5
QLocale::NorthernFrisian (since Qt 6.5)331 
QLocale::NorthernLuri205Since Qt 5.7
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::Odia215Since 6.0
QLocale::Ojibwa216 
QLocale::OldIrish217Since Qt 5.1
QLocale::OldNorse218Since Qt 5.1
QLocale::OldPersian219Since Qt 5.1
QLocale::OriyaOdiaObsolete, please use Odia
QLocale::Oromo220 
QLocale::Osage221Since Qt 5.7
QLocale::Ossetic222 
QLocale::Pahlavi223Since Qt 5.1
QLocale::Palauan224Since Qt 5.7
QLocale::Pali225 
QLocale::Papiamento226Since Qt 5.7
QLocale::Pashto227 
QLocale::Persian228 
QLocale::Phoenician229Since Qt 5.1
QLocale::Pijin (since Qt 6.5)335 
QLocale::Polish230 
QLocale::Portuguese231 
QLocale::Prussian232Since Qt 5.5
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::Santali248Since Qt 5.1
QLocale::Sardinian249 
QLocale::Saurashtra250Since Qt 5.1
QLocale::Sena251 
QLocale::Serbian252 
QLocale::Shambala253 
QLocale::Shona254 
QLocale::SichuanYi255 
QLocale::Sicilian256Since Qt 5.12
QLocale::Sidamo257 
QLocale::Silesian258Since Qt 5.14
QLocale::Sindhi259 
QLocale::Sinhala260 
QLocale::SkoltSami261Since Qt 5.5
QLocale::Slovak262 
QLocale::Slovenian263 
QLocale::Soga264 
QLocale::Somali265 
QLocale::SouthernKurdish266Since Qt 5.12
QLocale::SouthernSami267Since Qt 5.5
QLocale::SouthernSotho268 
QLocale::SouthNdebele269 
QLocale::Spanish270 
QLocale::StandardMoroccanTamazight271Since Qt 5.3
QLocale::Sundanese272 
QLocale::Swahili273 
QLocale::Swati274 
QLocale::Swedish275 
QLocale::SwissGerman276 
QLocale::Syriac277 
QLocale::Tachelhit278 
QLocale::Tahitian279 
QLocale::TaiDam280Since Qt 5.1
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::TokelauLanguage293Since Qt 5.7
QLocale::TokiPona (since Qt 6.5)334 
QLocale::TokPisin294Since Qt 5.7
QLocale::Tongan295 
QLocale::Torwali (since Qt 6.6)340 
QLocale::Tsonga296 
QLocale::Tswana297 
QLocale::Turkish298 
QLocale::Turkmen299 
QLocale::TuvaluLanguage300Since Qt 5.7
QLocale::Tyap301 
QLocale::Ugaritic302Since Qt 5.1
QLocale::UighurUyghurObsolete, please use Uyghur
QLocale::UigurUyghurObsolete, please use Uyghur
QLocale::Ukrainian303 
QLocale::UpperSorbian304Since Qt 5.5
QLocale::Urdu305 
QLocale::Uyghur306Since 6.0
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::Warlpiri315Since Qt 5.5
QLocale::Welsh316 
QLocale::WesternBalochi317Since Qt 5.12
QLocale::WesternFrisian318same as Frisian
QLocale::Wolaytta319Since 6.0
QLocale::Wolof320 
QLocale::Xhosa321 
QLocale::Yangben322 
QLocale::Yiddish323 
QLocale::Yoruba324 
QLocale::Zarma325 
QLocale::Zhuang326 
QLocale::Zulu327 

See also language() and languageToString().

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::AdlamScript1Since Qt 5.7
QLocale::AhomScript2Since Qt 5.7
QLocale::AnatolianHieroglyphsScript3Since Qt 5.7
QLocale::ArabicScript4 
QLocale::ArmenianScript5 
QLocale::AvestanScript6Since Qt 5.1
QLocale::BalineseScript7Since Qt 5.1
QLocale::BamumScript8Since Qt 5.1
QLocale::BanglaScript9Since 6.0
QLocale::BassaVahScript10Since Qt 5.5
QLocale::BatakScript11Since Qt 5.1
QLocale::BengaliScriptBanglaScriptObsolete, please use BanglaScript
QLocale::BhaiksukiScript12Since Qt 5.7
QLocale::BopomofoScript13Since Qt 5.1
QLocale::BrahmiScript14Since Qt 5.1
QLocale::BrailleScript15Since Qt 5.1
QLocale::BugineseScript16Since Qt 5.1
QLocale::BuhidScript17Since Qt 5.1
QLocale::CanadianAboriginalScript18Since Qt 5.1
QLocale::CarianScript19Since Qt 5.1
QLocale::CaucasianAlbanianScript20Since Qt 5.5
QLocale::ChakmaScript21Since Qt 5.1
QLocale::ChamScript22Since Qt 5.1
QLocale::CherokeeScript23 
QLocale::CopticScript24Since Qt 5.1
QLocale::CuneiformScript25Since Qt 5.1
QLocale::CypriotScript26Since Qt 5.1
QLocale::CyrillicScript27 
QLocale::DeseretScript28Since Qt 5.1
QLocale::DevanagariScript29 
QLocale::DuployanScript30Since Qt 5.5
QLocale::EgyptianHieroglyphsScript31Since Qt 5.1
QLocale::ElbasanScript32Since Qt 5.5
QLocale::EthiopicScript33 
QLocale::FraserScript34Since Qt 5.1
QLocale::GeorgianScript35 
QLocale::GlagoliticScript36Since Qt 5.1
QLocale::GothicScript37Since Qt 5.1
QLocale::GranthaScript38Since Qt 5.5
QLocale::GreekScript39 
QLocale::GujaratiScript40 
QLocale::GurmukhiScript41 
QLocale::HangulScript42Since Qt 5.1
QLocale::HanScript43Since Qt 5.1
QLocale::HanunooScript44Since Qt 5.1
QLocale::HanWithBopomofoScript45Since Qt 5.7
QLocale::HatranScript46Since Qt 5.7
QLocale::HebrewScript47 
QLocale::HiraganaScript48Since Qt 5.1
QLocale::ImperialAramaicScript49Since Qt 5.1
QLocale::InscriptionalPahlaviScript50Since Qt 5.1
QLocale::InscriptionalParthianScript51Since Qt 5.1
QLocale::JamoScript52Since Qt 5.7
QLocale::JapaneseScript53 
QLocale::JavaneseScript54Since Qt 5.1
QLocale::KaithiScript55Since Qt 5.1
QLocale::KannadaScript56 
QLocale::KatakanaScript57Since Qt 5.1
QLocale::KayahLiScript58Since Qt 5.1
QLocale::KharoshthiScript59Since Qt 5.1
QLocale::KhmerScript60Since Qt 5.1
QLocale::KhojkiScript61Since Qt 5.5
QLocale::KhudawadiScript62Since Qt 5.5
QLocale::KoreanScript63 
QLocale::LannaScript64Since Qt 5.1
QLocale::LaoScript65 
QLocale::LatinScript66 
QLocale::LepchaScript67Since Qt 5.1
QLocale::LimbuScript68Since Qt 5.1
QLocale::LinearAScript69Since Qt 5.5
QLocale::LinearBScript70Since Qt 5.1
QLocale::LycianScript71Since Qt 5.1
QLocale::LydianScript72Since Qt 5.1
QLocale::MahajaniScript73Since Qt 5.5
QLocale::MalayalamScript74 
QLocale::MandaeanScript75Since Qt 5.1
QLocale::ManichaeanScript76Since Qt 5.5
QLocale::MarchenScript77Since Qt 5.7
QLocale::MeiteiMayekScript78Since Qt 5.1
QLocale::MendeScript79Since Qt 6.0
QLocale::MendeKikakuiScriptMendeScriptObsolete, please use MendeScript
QLocale::MeroiticCursiveScript80Since Qt 5.1
QLocale::MeroiticScript81Since Qt 5.1
QLocale::ModiScript82Since Qt 5.5
QLocale::MongolianScript83 
QLocale::MroScript84Since Qt 5.5
QLocale::MultaniScript85Since Qt 5.7
QLocale::MyanmarScript86 
QLocale::NabataeanScript87Since Qt 5.5
QLocale::NewaScript88Since Qt 5.7
QLocale::NewTaiLueScript89Since Qt 5.1
QLocale::NkoScript90Since Qt 5.1
QLocale::OghamScript92Since Qt 5.1
QLocale::OlChikiScript93Since Qt 5.1
QLocale::OldHungarianScript94Since Qt 5.7
QLocale::OldItalicScript95Since Qt 5.1
QLocale::OldNorthArabianScript96Since Qt 5.5
QLocale::OldPermicScript97Since Qt 5.5
QLocale::OldPersianScript98Since Qt 5.1
QLocale::OldSouthArabianScript99Since Qt 5.1
QLocale::OdiaScript91Since 6.0
QLocale::OriyaScriptOdiaScriptObsolete, please use OdiaScript
QLocale::OrkhonScript100Since Qt 5.1
QLocale::OsageScript101Since Qt 5.7
QLocale::OsmanyaScript102Since Qt 5.1
QLocale::PahawhHmongScript103Since Qt 5.5
QLocale::PalmyreneScript104Since Qt 5.5
QLocale::PauCinHauScript105Since Qt 5.5
QLocale::PhagsPaScript106Since Qt 5.1
QLocale::PhoenicianScript107Since Qt 5.1
QLocale::PollardPhoneticScript108Since Qt 5.1
QLocale::PsalterPahlaviScript109Since Qt 5.5
QLocale::RejangScript110Since Qt 5.1
QLocale::RunicScript111Since Qt 5.1
QLocale::SamaritanScript112Since Qt 5.1
QLocale::SaurashtraScript113Since Qt 5.1
QLocale::SharadaScript114Since Qt 5.1
QLocale::ShavianScript115Since Qt 5.1
QLocale::SiddhamScript116Since Qt 5.5
QLocale::SignWritingScript117Since Qt 5.7
QLocale::SimplifiedChineseScriptSimplifiedHanScriptsame as SimplifiedHanScript
QLocale::SimplifiedHanScript118same as SimplifiedChineseScript
QLocale::SinhalaScript119 
QLocale::SoraSompengScript120Since Qt 5.1
QLocale::SundaneseScript121Since Qt 5.1
QLocale::SylotiNagriScript122Since Qt 5.1
QLocale::SyriacScript123 
QLocale::TagalogScript124Since Qt 5.1
QLocale::TagbanwaScript125Since Qt 5.1
QLocale::TaiLeScript126Since Qt 5.1
QLocale::TaiVietScript127Since Qt 5.1
QLocale::TakriScript128Since Qt 5.1
QLocale::TamilScript129 
QLocale::TangutScript130Since Qt 5.7
QLocale::TeluguScript131 
QLocale::ThaanaScript132 
QLocale::ThaiScript133 
QLocale::TibetanScript134 
QLocale::TifinaghScript135 
QLocale::TirhutaScript136Since Qt 5.5
QLocale::TraditionalChineseScriptTraditionalHanScriptsame as TraditionalHanScript
QLocale::TraditionalHanScript137same as TraditionalChineseScript
QLocale::UgariticScript138Since Qt 5.1
QLocale::VaiScript139 
QLocale::VarangKshitiScript140Since Qt 5.5
QLocale::YiScript141 

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

[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(const QLocale &other)

Constructs a QLocale object as a copy of other.

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.

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(const QString &name)

Constructs a QLocale object with the specified name, which 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).

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

QLocale::QLocale()

Constructs a QLocale object initialized with the default locale.

If no default locale was set using setDefault(), this locale will be the same as the one returned by system().

See also setDefault().

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

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

QLocale::~QLocale()

Destructor

QString QLocale::amText() const

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

See also pmText().

QString QLocale::bcp47Name() const

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

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

This function tries to conform the locale name to BCP47.

See also 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, since 6.1] QLocale::Language QLocale::codeToLanguage(QStringView languageCode)

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

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

This function was introduced in Qt 6.1.

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

[static, 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, 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().

[since 5.13] QLocale QLocale::collation() const

Returns the locale to use for collation.

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

This function was introduced in Qt 5.13.

See also QCollator.

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 decimal point character of this locale.

See also groupSeparator() and toString().

QString QLocale::exponential() const

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

See also toString(double, char, int).

Qt::DayOfWeek QLocale::firstDayOfWeek() const

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

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

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

This function was introduced in Qt 5.10.

QString QLocale::groupSeparator() const

Returns the group separator character of this locale.

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.1] QString QLocale::languageToCode(QLocale::Language language)

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

Note: For QLocale::C the function returns "C". For QLocale::AnyLanguage an empty string is returned.

This function was introduced in Qt 6.1.

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

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

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

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

QString QLocale::nativeLanguageName() const

Returns a native name of the language for the locale. For example "Schwiizertüütsch" for 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 character of this locale.

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 character of this locale.

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 character of this locale.

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

[since 5.6] void QLocale::swap(QLocale &other)

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

This function was introduced in Qt 5.6.

[static] QLocale QLocale::system()

Returns a QLocale object initialized to the system locale.

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(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(ushort value, const QString &symbol = QString()) const

This is an overloaded function.

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

[since 5.7] 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.

This function was introduced in Qt 5.7.

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) const

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

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

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

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

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

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

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

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

[since 5.14] QDate QLocale::toDate(const QString &string, QLocale::FormatType format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

[since 5.14] QDate QLocale::toDate(const QString &string, const QString &format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

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

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

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

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

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

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

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

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

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

[since 5.14] QDateTime QLocale::toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

[since 5.14] QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCalendar cal) const

This is an overloaded function.

This function was introduced in Qt 5.14.

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

Returns the double represented by the localized string s.

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

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

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

bool ok;
double d;

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

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

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

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

This function ignores leading and trailing whitespace.

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

[since 5.10] double QLocale::toDouble(QStringView s, bool *ok = nullptr) const

Returns the double represented by the localized string s.

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

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

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

bool ok;
double d;

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

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

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

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

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

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

Returns the float represented by the localized string s.

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

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

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

This function ignores leading and trailing whitespace.

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

[since 5.10] float QLocale::toFloat(QStringView s, bool *ok = nullptr) const

Returns the float represented by the localized string s.

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

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

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

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

Returns the int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toUInt() and toString().

[since 5.10] int QLocale::toInt(QStringView s, bool *ok = nullptr) const

Returns the int represented by the localized string s.

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toUInt() and toString().

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

Returns the long int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

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

[since 5.13] long QLocale::toLong(QStringView s, bool *ok = nullptr) const

Returns the long int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

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

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

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

[since 5.10] qlonglong QLocale::toLongLong(QStringView s, bool *ok = nullptr) const

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

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

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

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

Returns a lowercase copy of str.

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

See also QString::toLower().

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

Returns the short int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toUShort() and toString().

[since 5.10] short QLocale::toShort(QStringView s, bool *ok = nullptr) const

Returns the short int represented by the localized string s.

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toUShort() and toString().

QString QLocale::toString(qlonglong i) const

Returns a localized string representation of i.

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

QString QLocale::toString(qulonglong i) const

This is an overloaded function.

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

QString QLocale::toString(long i) const

This is an overloaded function.

See also toLong().

QString QLocale::toString(ulong i) const

This is an overloaded function.

See also toULong().

QString QLocale::toString(short i) const

This is an overloaded function.

See also toShort().

QString QLocale::toString(ushort i) const

This is an overloaded function.

See also toUShort().

QString QLocale::toString(int i) const

This is an overloaded function.

See also toInt().

QString QLocale::toString(uint i) const

This is an overloaded function.

See also toUInt().

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

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

[since 5.10] QString QLocale::toString(QDate date, QStringView format) const

This is an overloaded function.

This function was introduced in Qt 5.10.

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

[since 5.10] QString QLocale::toString(const QDateTime &dateTime, QStringView format) const

This is an overloaded function.

This function was introduced in Qt 5.10.

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

This is an overloaded function.

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(const QDateTime &dateTime, QLocale::FormatType format = LongFormat) const

This is an overloaded function.

[since 5.14] 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.

This function was introduced in Qt 5.14.

See also QDate::toString().

[since 5.14] 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.

This function was introduced in Qt 5.14.

[since 5.14] QString QLocale::toString(const QDateTime &dateTime, QLocale::FormatType format, QCalendar cal) const

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

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

This function was introduced in Qt 5.14.

[since 5.14] QString QLocale::toString(const QDateTime &dateTime, QStringView format, QCalendar cal) const

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

This function was introduced in Qt 5.14.

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

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

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

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

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

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

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

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

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

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

Returns the unsigned int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toInt() and toString().

[since 5.10] uint QLocale::toUInt(QStringView s, bool *ok = nullptr) const

Returns the unsigned int represented by the localized string s.

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toInt() and toString().

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

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

[since 5.13] ulong QLocale::toULong(QStringView s, bool *ok = nullptr) const

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.13.

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

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

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

[since 5.10] qulonglong QLocale::toULongLong(QStringView s, bool *ok = nullptr) const

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

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

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

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toShort() and toString().

[since 5.10] ushort QLocale::toUShort(QStringView s, bool *ok = nullptr) const

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

If the conversion fails, the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.10.

See also toShort() and toString().

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

Returns an uppercase copy of str.

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

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

See also QString::toUpper().

QStringList QLocale::uiLanguages() const

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

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

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

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

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.

See also toString().

Related Non-Members

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

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

This function was introduced in Qt 5.6.

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

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.