QLocale Class

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

Header: #include <QLocale>
qmake: QT += core

Note: All functions in this class are reentrant, except for setDefault(), which is nonreentrant.

Public Types

enum Country { AnyCountry, Afghanistan, Albania, Algeria, ..., SintMaarten }
enum CurrencySymbolFormat { CurrencyIsoCode, CurrencySymbol, CurrencyDisplayName }
enum FormatType { LongFormat, ShortFormat, NarrowFormat }
enum Language { AnyLanguage, C, Abkhazian, Oromo, ..., Ugaritic }
enum MeasurementSystem { MetricSystem, ImperialUSSystem, ImperialUKSystem, ImperialSystem }
enum NumberOption { OmitGroupSeparator, RejectGroupSeparator }
flags NumberOptions
enum QuotationStyle { StandardQuotation, AlternateQuotation }
enum Script { AnyScript, ArabicScript, ArmenianScript, AvestanScript, ..., YiScript }

Public Functions

QLocale()
QLocale(const QString & name)
QLocale(Language language, Country country = AnyCountry)
QLocale(Language language, Script script, Country country)
QLocale(const QLocale & other)
~QLocale()
QString amText() const
QString bcp47Name() const
Country country() const
QString createSeparatedList(const QStringList & list) const
QString currencySymbol(CurrencySymbolFormat format = CurrencySymbol) const
QString dateFormat(FormatType format = LongFormat) const
QString dateTimeFormat(FormatType format = LongFormat) const
QString dayName(int day, FormatType type = LongFormat) const
QChar decimalPoint() const
QChar exponential() const
Qt::DayOfWeek firstDayOfWeek() const
QChar groupSeparator() const
Language language() const
MeasurementSystem measurementSystem() const
QString monthName(int month, FormatType type = LongFormat) const
QString name() const
QString nativeCountryName() const
QString nativeLanguageName() const
QChar negativeSign() const
NumberOptions numberOptions() const
QChar percent() const
QString pmText() const
QChar positiveSign() const
QString quoteString(const QString & str, QuotationStyle style = StandardQuotation) const
QString quoteString(const QStringRef & str, QuotationStyle style = StandardQuotation) const
Script script() const
void setNumberOptions(NumberOptions options)
QString standaloneDayName(int day, FormatType type = LongFormat) const
QString standaloneMonthName(int month, FormatType type = LongFormat) const
Qt::LayoutDirection textDirection() const
QString timeFormat(FormatType format = LongFormat) const
QString toCurrencyString(qlonglong value, const QString & symbol = QString()) const
QString toCurrencyString(qulonglong value, const QString & symbol = QString()) const
QString toCurrencyString(double 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(float value, const QString & symbol = QString()) const
QDate toDate(const QString & string, FormatType format = LongFormat) const
QDate toDate(const QString & string, const QString & format) const
QDateTime toDateTime(const QString & string, FormatType format = LongFormat) const
QDateTime toDateTime(const QString & string, const QString & format) const
double toDouble(const QString & s, bool * ok = 0) const
double toDouble(const QStringRef & s, bool * ok = 0) const
float toFloat(const QString & s, bool * ok = 0) const
float toFloat(const QStringRef & s, bool * ok = 0) const
int toInt(const QString & s, bool * ok = 0) const
int toInt(const QStringRef & s, bool * ok = 0) const
qlonglong toLongLong(const QString & s, bool * ok = 0) const
qlonglong toLongLong(const QStringRef & s, bool * ok = 0) const
QString toLower(const QString & str) const
short toShort(const QString & s, bool * ok = 0) const
short toShort(const QStringRef & s, bool * ok = 0) const
QString toString(qlonglong i) const
QString toString(const QDate & date, const QString & format) const
QString toString(const QDate & date, FormatType format = LongFormat) const
QString toString(const QTime & time, const QString & format) const
QString toString(const QTime & time, FormatType format = LongFormat) const
QString toString(const QDateTime & dateTime, FormatType format = LongFormat) const
QString toString(const QDateTime & dateTime, const QString & format) const
QString toString(qulonglong i) const
QString toString(double i, char f = 'g', int prec = 6) const
QString toString(short i) const
QString toString(ushort i) const
QString toString(int i) const
QString toString(uint i) const
QString toString(float i, char f = 'g', int prec = 6) const
QTime toTime(const QString & string, FormatType format = LongFormat) const
QTime toTime(const QString & string, const QString & format) const
uint toUInt(const QString & s, bool * ok = 0) const
uint toUInt(const QStringRef & s, bool * ok = 0) const
qulonglong toULongLong(const QString & s, bool * ok = 0) const
qulonglong toULongLong(const QStringRef & s, bool * ok = 0) const
ushort toUShort(const QString & s, bool * ok = 0) const
ushort toUShort(const QStringRef & s, bool * ok = 0) const
QString toUpper(const QString & str) const
QStringList uiLanguages() const
QList<Qt::DayOfWeek> weekdays() const
QChar zeroDigit() const
bool operator!=(const QLocale & other) const
QLocale & operator=(const QLocale & other)
bool operator==(const QLocale & other) const

Static Public Members

QLocale c()
QString countryToString(Country country)
QString languageToString(Language language)
QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country)
QString scriptToString(Script script)
void setDefault(const QLocale & locale)
QLocale system()

Detailed Description

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

QLocale is initialized with a language/country pair in its constructor and offers number-to-string and string-to-number conversion functions similar to those in QString.

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::toInt(), QString::toDouble(), etc., interpret the string according to the default locale. If this fails, it falls back on the "C" locale.
  • 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:

QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel));
QLocale hebrew; // Constructs a default QLocale
QString s1 = hebrew.toString(15714.3, 'e');

bool ok;
double d;

QLocale::setDefault(QLocale::C);
d = QString("1234,56").toDouble(&ok);   // ok == false
d = QString("1234.56").toDouble(&ok);   // ok == true, d == 1234.56

QLocale::setDefault(QLocale::German);
d = QString("1234,56").toDouble(&ok);   // ok == true, d == 1234.56
d = QString("1234.56").toDouble(&ok);   // ok == true, d == 1234.56

QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
str = QString("%1 %L2 %L3")
      .arg(12345).arg(12345).arg(12345, 0, 16);
// str == "12345 12,345 3039"

When a language/country pair is specified in the constructor, one of three things can happen:

  • If the language/country pair is found in the database, it is used.
  • If the language is found but the country is not, or if the country is AnyCountry, the language is used with the most appropriate available country (for example, Germany for German),
  • If neither the language nor the country are found, QLocale defaults to the default locale (see setDefault()).

Use language() and country() to determine the actual language and country values used.

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

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

This constructor converts the locale name to a language/country pair; it does not use the system locale database.

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

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

The double-to-string and string-to-double conversion functions are covered by the following licenses:

Copyright (c) 1991 by AT&T.

Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.

THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.

This product includes software developed by the University of California, Berkeley and its contributors.

See also QString::arg(), QString::toInt(), QString::toDouble(), and QInputMethod::locale().

Member Type Documentation

enum QLocale::​Country

This enumerated type is used to specify a country.

ConstantValueDescription
QLocale::AnyCountry0 
QLocale::Afghanistan1 
QLocale::Albania2 
QLocale::Algeria3 
QLocale::AmericanSamoa4 
QLocale::Andorra5 
QLocale::Angola6 
QLocale::Anguilla7 
QLocale::Antarctica8 
QLocale::AntiguaAndBarbuda9 
QLocale::Argentina10 
QLocale::Armenia11 
QLocale::Aruba12 
QLocale::Australia13 
QLocale::Austria14 
QLocale::Azerbaijan15 
QLocale::Bahamas16 
QLocale::Bahrain17 
QLocale::Bangladesh18 
QLocale::Barbados19 
QLocale::Belarus20 
QLocale::Belgium21 
QLocale::Belize22 
QLocale::Benin23 
QLocale::Bermuda24 
QLocale::Bhutan25 
QLocale::Bolivia26 
QLocale::BosniaAndHerzegowina27 
QLocale::Botswana28 
QLocale::BouvetIsland29 
QLocale::Brazil30 
QLocale::BritishIndianOceanTerritory31 
QLocale::Brunei32 
QLocale::Bulgaria33 
QLocale::BurkinaFaso34 
QLocale::Burundi35 
QLocale::Cambodia36 
QLocale::Cameroon37 
QLocale::Canada38 
QLocale::CanaryIslands238 
QLocale::CapeVerde39 
QLocale::CaymanIslands40 
QLocale::CentralAfricanRepublic41 
QLocale::Chad42 
QLocale::Chile43 
QLocale::China44 
QLocale::ChristmasIsland45 
QLocale::ClippertonIsland241 
QLocale::CocosIslands46 
QLocale::Colombia47 
QLocale::Comoros48 
QLocale::CongoKinshasa49 
QLocale::CongoBrazzaville50 
QLocale::DemocraticRepublicOfCongoCongoKinshasaObsolete, please use CongoKinshasa
QLocale::PeoplesRepublicOfCongoCongoBrazzavilleObsolete, please use CongoBrazzaville
QLocale::CookIslands51 
QLocale::CostaRica52 
QLocale::IvoryCoast53 
QLocale::Croatia54 
QLocale::Cuba55 
QLocale::Cyprus56 
QLocale::CzechRepublic57 
QLocale::Denmark58 
QLocale::Djibouti59 
QLocale::Dominica60 
QLocale::DominicanRepublic61 
QLocale::EastTimor62 
QLocale::Ecuador63 
QLocale::Egypt64 
QLocale::ElSalvador65 
QLocale::EquatorialGuinea66 
QLocale::Eritrea67 
QLocale::Estonia68 
QLocale::Ethiopia69 
QLocale::FalklandIslands70 
QLocale::FaroeIslands71 
QLocale::Fiji72 
QLocale::Finland73 
QLocale::France74 
QLocale::FrenchGuiana76 
QLocale::FrenchPolynesia77 
QLocale::FrenchSouthernTerritories78 
QLocale::Gabon79 
QLocale::Gambia80 
QLocale::Georgia81 
QLocale::Germany82 
QLocale::Ghana83 
QLocale::Gibraltar84 
QLocale::Greece85 
QLocale::Greenland86 
QLocale::Grenada87 
QLocale::Guadeloupe88 
QLocale::Guam89 
QLocale::Guatemala90 
QLocale::Guernsey75 
QLocale::Guinea91 
QLocale::GuineaBissau92 
QLocale::Guyana93 
QLocale::Haiti94 
QLocale::HeardAndMcDonaldIslands95 
QLocale::Honduras96 
QLocale::HongKong97 
QLocale::Hungary98 
QLocale::Iceland99 
QLocale::India100 
QLocale::Indonesia101 
QLocale::Iran102 
QLocale::Iraq103 
QLocale::Ireland104 
QLocale::Israel105 
QLocale::Italy106 
QLocale::Jamaica107 
QLocale::Japan108 
QLocale::Jordan109 
QLocale::Kazakhstan110 
QLocale::Kenya111 
QLocale::Kiribati112 
QLocale::NorthKorea113 
QLocale::SouthKorea114 
QLocale::DemocraticRepublicOfKoreaNorthKoreaObsolete, please use NorthKorea
QLocale::RepublicOfKoreaSouthKoreaObsolete, please use SouthKorea
QLocale::Kosovo257 
QLocale::Kuwait115 
QLocale::Kyrgyzstan116 
QLocale::Laos117 
QLocale::Latvia118 
QLocale::Lebanon119 
QLocale::Lesotho120 
QLocale::Liberia121 
QLocale::Libya122 
QLocale::Liechtenstein123 
QLocale::Lithuania124 
QLocale::Luxembourg125 
QLocale::Macau126 
QLocale::Macedonia127 
QLocale::Madagascar128 
QLocale::Malawi129 
QLocale::Malaysia130 
QLocale::Maldives131 
QLocale::Mali132 
QLocale::Malta133 
QLocale::MarshallIslands134 
QLocale::Martinique135 
QLocale::Mauritania136 
QLocale::Mauritius137 
QLocale::Mayotte138 
QLocale::Mexico139 
QLocale::Micronesia140 
QLocale::Moldova141 
QLocale::Monaco142 
QLocale::Mongolia143 
QLocale::Montserrat144 
QLocale::Morocco145 
QLocale::Mozambique146 
QLocale::Myanmar147 
QLocale::Namibia148 
QLocale::NauruCountry149 
QLocale::Nepal150 
QLocale::Netherlands151 
QLocale::NewCaledonia153 
QLocale::NewZealand154 
QLocale::Nicaragua155 
QLocale::Niger156 
QLocale::Nigeria157 
QLocale::Niue158 
QLocale::NorfolkIsland159 
QLocale::NorthernMarianaIslands160 
QLocale::Norway161 
QLocale::Oman162 
QLocale::Pakistan163 
QLocale::Palau164 
QLocale::PalestinianTerritories165 
QLocale::Panama166 
QLocale::PapuaNewGuinea167 
QLocale::Paraguay168 
QLocale::Peru169 
QLocale::Philippines170 
QLocale::Pitcairn171 
QLocale::Poland172 
QLocale::Portugal173 
QLocale::PuertoRico174 
QLocale::Qatar175 
QLocale::Reunion176 
QLocale::Romania177 
QLocale::Russia178same as RussianFederation
QLocale::RussianFederationRussiasame as Russia
QLocale::Rwanda179 
QLocale::SaintKittsAndNevis180 
QLocale::SaintLucia181 
QLocale::SaintVincentAndTheGrenadines182 
QLocale::Samoa183 
QLocale::SanMarino184 
QLocale::SaoTomeAndPrincipe185 
QLocale::SaudiArabia186 
QLocale::Senegal187 
QLocale::Seychelles188 
QLocale::SierraLeone189 
QLocale::Singapore190 
QLocale::Slovakia191 
QLocale::Slovenia192 
QLocale::SolomonIslands193 
QLocale::Somalia194 
QLocale::SouthAfrica195 
QLocale::SouthGeorgiaAndTheSouthSandwichIslands196 
QLocale::Spain197 
QLocale::SriLanka198 
QLocale::SaintHelena199 
QLocale::SaintPierreAndMiquelon200 
QLocale::Sudan201 
QLocale::Suriname202 
QLocale::SvalbardAndJanMayenIslands203 
QLocale::Swaziland204 
QLocale::Sweden205 
QLocale::Switzerland206 
QLocale::Syria207 
QLocale::SyrianArabRepublicSyriaObsolete, please use Syria
QLocale::Taiwan208 
QLocale::Tajikistan209 
QLocale::Tanzania210 
QLocale::Thailand211 
QLocale::Togo212 
QLocale::Tokelau213 
QLocale::Tonga214 
QLocale::TrinidadAndTobago215 
QLocale::Tunisia216 
QLocale::Turkey217 
QLocale::Turkmenistan218 
QLocale::TurksAndCaicosIslands219 
QLocale::Tuvalu220 
QLocale::Uganda221 
QLocale::Ukraine222 
QLocale::UnitedArabEmirates223 
QLocale::UnitedKingdom224 
QLocale::UnitedStates225 
QLocale::UnitedStatesMinorOutlyingIslands226 
QLocale::Uruguay227 
QLocale::Uzbekistan228 
QLocale::Vanuatu229 
QLocale::VaticanCityState230 
QLocale::Venezuela231 
QLocale::Vietnam232 
QLocale::BritishVirginIslands233 
QLocale::UnitedStatesVirginIslands234 
QLocale::WallisAndFutunaIslands235 
QLocale::WesternSahara236 
QLocale::Yemen237 
QLocale::Zambia239 
QLocale::Zimbabwe240 
QLocale::Montenegro242 
QLocale::Serbia243 
QLocale::SaintBarthelemy244 
QLocale::SaintMartin245 
QLocale::LatinAmericaAndTheCaribbean246 
QLocale::AscensionIsland247 
QLocale::AlandIslands248 
QLocale::DiegoGarcia249 
QLocale::CeutaAndMelilla250 
QLocale::IsleOfMan251 
QLocale::Jersey252 
QLocale::TristanDaCunha253 
QLocale::SouthSudan254 
QLocale::CuraSao152 
QLocale::Bonaire255 
QLocale::SintMaarten256 

See also country() and countryToString().

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.

This enum was introduced or modified in Qt 4.8.

enum QLocale::​FormatType

This enum describes the types of format that can be used when converting QDate and QTime objects to strings.

ConstantValueDescription
QLocale::LongFormat0The long version of day and month names; for example, returning "January" as a month name.
QLocale::ShortFormat1The short version of day and month names; for example, returning "Jan" as a month name.
QLocale::NarrowFormat2A special version of day and month names for use when space is limited; for example, returning "J" as a month name. Note that the narrow format might contain the same text for different months and days or 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.

enum QLocale::​Language

This enumerated type is used to specify a language.

ConstantValueDescription
QLocale::AnyLanguage0 
QLocale::C1The "C" locale is identical in behavior to English/UnitedStates.
QLocale::Abkhazian2 
QLocale::Oromo3 
QLocale::AfanOromoObsolete, please use Oromo
QLocale::Afar4 
QLocale::Afrikaans5 
QLocale::Akoose312Since Qt 5.3
QLocale::Albanian6 
QLocale::Amharic7 
QLocale::Arabic8 
QLocale::Armenian9 
QLocale::Assamese10 
QLocale::Avaric216 
QLocale::Aymara11 
QLocale::Azerbaijani12 
QLocale::Bashkir13 
QLocale::Basque14 
QLocale::Bengali15 
QLocale::Dzongkha16 
QLocale::BhutaniDzongkhaObsolete, please use Dzongkha
QLocale::Bihari17 
QLocale::Bislama18 
QLocale::Bosnian142 
QLocale::Bodo215 
QLocale::Breton19 
QLocale::Bulgarian20 
QLocale::Burmese21 
QLocale::Belarusian22 
QLocale::ByelorussianBelarusianObsolete, please use Belarusian
QLocale::Khmer23 
QLocale::CambodianKhmerObsolete, please use Khmer
QLocale::Catalan24 
QLocale::Chamorro217 
QLocale::Chechen218 
QLocale::Chinese25 
QLocale::Church219 
QLocale::Chuvash220 
QLocale::Cornish145 
QLocale::Corsican26 
QLocale::Cree221 
QLocale::Croatian27 
QLocale::Czech28 
QLocale::Danish29 
QLocale::Divehi143 
QLocale::Dutch30 
QLocale::English31 
QLocale::Esperanto32 
QLocale::Estonian33 
QLocale::Faroese34 
QLocale::Fijian35 
QLocale::Finnish36 
QLocale::French37 
QLocale::WesternFrisian38same as Frisian
QLocale::FrisianWesternFrisiansame as WesternFrisian
QLocale::Gaelic39 
QLocale::Galician40 
QLocale::Georgian41 
QLocale::German42 
QLocale::Greek43 
QLocale::Greenlandic44 
QLocale::Guarani45 
QLocale::Gujarati46 
QLocale::Haitian222 
QLocale::Hausa47 
QLocale::Hebrew48 
QLocale::Herero223 
QLocale::Hindi49 
QLocale::HiriMotu224 
QLocale::Hungarian50 
QLocale::Icelandic51 
QLocale::Indonesian52 
QLocale::Interlingua53 
QLocale::Interlingue54 
QLocale::Inuktitut55 
QLocale::Inupiak56 
QLocale::Irish57 
QLocale::Italian58 
QLocale::Japanese59 
QLocale::Javanese60 
QLocale::Kannada61 
QLocale::Kanuri225 
QLocale::Kashmiri62 
QLocale::Kazakh63 
QLocale::Kinyarwanda64 
QLocale::Kirghiz65 
QLocale::Komi226 
QLocale::Kongo227 
QLocale::Korean66 
QLocale::Kurdish67 
QLocale::Rundi68 
QLocale::KurundiRundiObsolete, please use Rundi
QLocale::Kwanyama228 
QLocale::Lakota313Since Qt 5.3
QLocale::Lao69 
QLocale::Latin70 
QLocale::Latvian71 
QLocale::Limburgish229 
QLocale::Lingala72 
QLocale::Lithuanian73 
QLocale::LubaKatanga230 
QLocale::Luxembourgish231 
QLocale::Marshallese81 
QLocale::Macedonian74 
QLocale::Malagasy75 
QLocale::Malay76 
QLocale::Malayalam77 
QLocale::Maltese78 
QLocale::Manx144 
QLocale::Maori79 
QLocale::Marathi80 
QLocale::MoldavianRomanianObsolete, please use Romanian
QLocale::Mongolian82 
QLocale::NauruLanguage83 
QLocale::Navaho232 
QLocale::Ndonga233 
QLocale::Nepali84 
QLocale::NorwegianNorwegianBokmalsame as NorwegianBokmal
QLocale::NorwegianBokmal85same as Norwegian
QLocale::NorwegianNynorsk141 
QLocale::Occitan86 
QLocale::Ojibwa234 
QLocale::Oriya87 
QLocale::Ossetic101 
QLocale::Pali235 
QLocale::Pashto88 
QLocale::Persian89 
QLocale::Polish90 
QLocale::Portuguese91 
QLocale::Punjabi92 
QLocale::Quechua93 
QLocale::Romansh94 
QLocale::RhaetoRomanceRomanshObsolete, please use Romansh
QLocale::Romanian95 
QLocale::Russian96 
QLocale::Samoan97 
QLocale::Sango98 
QLocale::Sanskrit99 
QLocale::Sardinian115 
QLocale::Serbian100 
QLocale::SerboCroatianSerbianObsolete, please use Serbian
QLocale::SouthernSotho102 
QLocale::Tswana103 
QLocale::Shona104 
QLocale::Sindhi105 
QLocale::Sinhala106 
QLocale::Swati107 
QLocale::Slovak108 
QLocale::Slovenian109 
QLocale::Somali110 
QLocale::Spanish111 
QLocale::StandardMoroccanTamazight314Since Qt 5.3
QLocale::Sundanese112 
QLocale::Swahili113 
QLocale::Swedish114 
QLocale::TagalogFilipinoObsolete, please use Filipino
QLocale::Tahitian127 
QLocale::Tajik116 
QLocale::Tamil117 
QLocale::Tatar118 
QLocale::Telugu119 
QLocale::Thai120 
QLocale::Tibetan121 
QLocale::Tigrinya122 
QLocale::Tongan123 
QLocale::Tsonga124 
QLocale::Turkish125 
QLocale::Turkmen126 
QLocale::TwiAkanObsolete, please use Akan
QLocale::Uighur128 
QLocale::UigurUighurObsolete, please use Uighur
QLocale::Ukrainian129 
QLocale::Urdu130 
QLocale::Uzbek131 
QLocale::Vietnamese132 
QLocale::Volapuk133 
QLocale::Walloon236 
QLocale::Welsh134 
QLocale::Wolof135 
QLocale::Xhosa136 
QLocale::Yiddish137 
QLocale::Yoruba138 
QLocale::Zhuang139 
QLocale::Zulu140 
QLocale::Bosnian142 
QLocale::Divehi143 
QLocale::Manx144 
QLocale::Cornish145 
QLocale::Akan146 
QLocale::Konkani147 
QLocale::Ga148 
QLocale::Igbo149 
QLocale::Kamba150 
QLocale::Syriac151 
QLocale::Blin152 
QLocale::Geez153 
QLocale::Koro154 
QLocale::Sidamo155 
QLocale::Atsam156 
QLocale::Tigre157 
QLocale::Jju158 
QLocale::Friulian159 
QLocale::Venda160 
QLocale::Ewe161 
QLocale::Walamo162 
QLocale::Hawaiian163 
QLocale::Tyap164 
QLocale::Nyanja165 
QLocale::ChewaNyanjaObsolete, please use Nyanja
QLocale::Filipino166 
QLocale::SwissGerman167 
QLocale::SichuanYi168 
QLocale::Kpelle169 
QLocale::LowGerman170 
QLocale::SouthNdebele171 
QLocale::NorthernSotho172 
QLocale::NorthernSami173 
QLocale::Taroko174 
QLocale::Gusii175 
QLocale::Taita176 
QLocale::Fulah177 
QLocale::Kikuyu178 
QLocale::Samburu179 
QLocale::Sena180 
QLocale::NorthNdebele181 
QLocale::Rombo182 
QLocale::Tachelhit183 
QLocale::Kabyle184 
QLocale::Nyankole185 
QLocale::Bena186 
QLocale::Vunjo187 
QLocale::Bambara188 
QLocale::Embu189 
QLocale::Cherokee190 
QLocale::Morisyen191 
QLocale::Makonde192 
QLocale::Langi193 
QLocale::Ganda194 
QLocale::Bemba195 
QLocale::Kabuverdianu196 
QLocale::Meru197 
QLocale::Kalenjin198 
QLocale::Nama199 
QLocale::Machame200 
QLocale::Colognian201 
QLocale::Masai202 
QLocale::Soga203 
QLocale::Luyia204 
QLocale::Asu205 
QLocale::Teso206 
QLocale::Saho207 
QLocale::KoyraChiini208 
QLocale::Rwa209 
QLocale::Luo210 
QLocale::Chiga211 
QLocale::CentralMoroccoTamazight212 
QLocale::KoyraboroSenni213 
QLocale::Shambala214 
QLocale::Aghem237 
QLocale::Basaa238 
QLocale::Zarma239 
QLocale::Duala240 
QLocale::JolaFonyi241 
QLocale::Ewondo242 
QLocale::Bafia243 
QLocale::MakhuwaMeetto244 
QLocale::Mundang245 
QLocale::Kwasio246 
QLocale::Nuer247 
QLocale::Sakha248 
QLocale::Sangu249 
QLocale::CongoSwahili250 
QLocale::Tasawaq251 
QLocale::Vai252 
QLocale::Walser253 
QLocale::Yangben254 
QLocale::Avestan255 
QLocale::Asturian256 
QLocale::Ngomba257 
QLocale::Kako258 
QLocale::Meta259 
QLocale::Ngiemboon260 
QLocale::Aragonese261 
QLocale::Akkadian262 
QLocale::AncientEgyptian263 
QLocale::AncientGreek264 
QLocale::Aramaic265 
QLocale::Balinese266 
QLocale::Bamun267 
QLocale::BatakToba268 
QLocale::Buginese269 
QLocale::Buhid270 
QLocale::Carian271 
QLocale::Chakma272 
QLocale::ClassicalMandaic273 
QLocale::Coptic274 
QLocale::Dogri275 
QLocale::EasternCham276 
QLocale::EasternKayah277 
QLocale::Etruscan278 
QLocale::Gothic279 
QLocale::Hanunoo280 
QLocale::Ingush281 
QLocale::LargeFloweryMiao282 
QLocale::Lepcha283 
QLocale::Limbu284 
QLocale::Lisu285 
QLocale::Lu286 
QLocale::Lycian287 
QLocale::Lydian288 
QLocale::Mandingo289 
QLocale::Manipuri290 
QLocale::Meroitic291 
QLocale::NorthernThai292 
QLocale::OldIrish293 
QLocale::OldNorse294 
QLocale::OldPersian295 
QLocale::OldTurkish296 
QLocale::Pahlavi297 
QLocale::Parthian298 
QLocale::Phoenician299 
QLocale::PrakritLanguage300 
QLocale::Rejang301 
QLocale::Sabaean302 
QLocale::Samaritan303 
QLocale::Santali304 
QLocale::Saurashtra305 
QLocale::Sora306 
QLocale::Sylheti307 
QLocale::Tagbanwa308 
QLocale::TaiDam309 
QLocale::TaiNua310 
QLocale::Ugaritic311 

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

This enum was introduced or modified in Qt 4.4.

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::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.

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

See also setNumberOptions() and numberOptions().

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.

This enum was introduced or modified in Qt 4.8.

See also quoteString().

enum QLocale::​Script

This enumerated type is used to specify a script.

ConstantValueDescription
QLocale::AnyScript0 
QLocale::ArabicScript1 
QLocale::ArmenianScript10 
QLocale::AvestanScript36 
QLocale::BalineseScript37 
QLocale::BamumScript38 
QLocale::BatakScript39 
QLocale::BengaliScript11 
QLocale::BopomofoScript40 
QLocale::BrahmiScript41 
QLocale::BrailleScript103 
QLocale::BugineseScript42 
QLocale::BuhidScript43 
QLocale::CanadianAboriginalScript44 
QLocale::CarianScript45 
QLocale::ChakmaScript46 
QLocale::ChamScript47 
QLocale::CherokeeScript12 
QLocale::CopticScript48 
QLocale::CypriotScript49 
QLocale::CyrillicScript2 
QLocale::DeseretScript3 
QLocale::DevanagariScript13 
QLocale::EgyptianHieroglyphsScript50 
QLocale::EthiopicScript14 
QLocale::FraserScript51 
QLocale::GeorgianScript15 
QLocale::GlagoliticScript52 
QLocale::GothicScript53 
QLocale::GreekScript16 
QLocale::GujaratiScript17 
QLocale::GurmukhiScript4 
QLocale::HanScript54 
QLocale::HangulScript55 
QLocale::HanunooScript56 
QLocale::HebrewScript18 
QLocale::HiraganaScript104 
QLocale::ImperialAramaicScript57 
QLocale::InscriptionalPahlaviScript58 
QLocale::InscriptionalParthianScript59 
QLocale::JapaneseScript19 
QLocale::JavaneseScript60 
QLocale::KaithiScript61 
QLocale::KannadaScript21 
QLocale::KatakanaScript62 
QLocale::KayahLiScript63 
QLocale::KharoshthiScript64 
QLocale::KhmerScript20 
QLocale::KoreanScript22 
QLocale::LannaScript65 
QLocale::LaoScript23 
QLocale::LatinScript7 
QLocale::LepchaScript66 
QLocale::LimbuScript67 
QLocale::LinearBScript68 
QLocale::LycianScript69 
QLocale::LydianScript70 
QLocale::MalayalamScript24 
QLocale::MandaeanScript71 
QLocale::MeiteiMayekScript72 
QLocale::MeroiticScript73 
QLocale::MeroiticCursiveScript74 
QLocale::MongolianScript8 
QLocale::MyanmarScript25 
QLocale::NkoScript75 
QLocale::NewTaiLueScript76 
QLocale::OghamScript77 
QLocale::OlChikiScript78 
QLocale::OldItalicScript79 
QLocale::OldPersianScript80 
QLocale::OldSouthArabianScript81 
QLocale::OriyaScript26 
QLocale::OrkhonScript82 
QLocale::OsmanyaScript83 
QLocale::PhagsPaScript84 
QLocale::PhoenicianScript85 
QLocale::PollardPhoneticScript86 
QLocale::RejangScript87 
QLocale::RunicScript88 
QLocale::SamaritanScript89 
QLocale::SaurashtraScript90 
QLocale::SharadaScript91 
QLocale::ShavianScript92 
QLocale::SimplifiedHanScript5same as SimplifiedChineseScript
QLocale::SimplifiedChineseScriptSimplifiedHanScriptsame as SimplifiedHanScript
QLocale::SinhalaScript32 
QLocale::SoraSompengScript93 
QLocale::CuneiformScript94 
QLocale::SundaneseScript95 
QLocale::SylotiNagriScript96 
QLocale::SyriacScript33 
QLocale::TagalogScript97 
QLocale::TagbanwaScript98 
QLocale::TaiLeScript99 
QLocale::TaiVietScript100 
QLocale::TakriScript101 
QLocale::TamilScript27 
QLocale::TeluguScript28 
QLocale::ThaanaScript29 
QLocale::ThaiScript30 
QLocale::TibetanScript31 
QLocale::TifinaghScript9 
QLocale::TraditionalHanScript6same as TraditionalChineseScript
QLocale::TraditionalChineseScriptTraditionalHanScriptsame as TraditionalHanScript
QLocale::UgariticScript102 
QLocale::VaiScript35 
QLocale::YiScript34 

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

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

QLocale::​QLocale(const QString & name)

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

  • language is a lowercase, two-letter, ISO 639 language code (also some three-letter codes),
  • script is a titlecase, four-letter, ISO 15924 script code,
  • country is an uppercase, two-letter, ISO 3166 country code (also "419" as defined by United Nations),
  • and codeset and modifier are ignored.

The separator can be either underscore or a minus sign.

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

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

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

See also bcp47Name().

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

Constructs a QLocale object with the specified language and country.

  • If the language/country pair is found in the database, it is used.
  • If the language is found but the country is not, or if the country is AnyCountry, the language is used with the most appropriate available country (for example, Germany for German),
  • If neither the language nor the country are found, QLocale defaults to the default locale (see setDefault()).

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

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

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

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

  • If the language/script/country is found in the database, it is used.
  • If both script is AnyScript and country is AnyCountry, the language is used with the most appropriate available script and country (for example, Germany for German),
  • If either script is AnyScript or country is AnyCountry, the language is used with the first locale that matches the given script and country.
  • If neither the language nor the country are found, QLocale defaults to the default locale (see setDefault()).

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

This function was introduced in Qt 4.8.

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

QLocale::​QLocale(const QLocale & other)

Constructs a QLocale object as a copy of other.

QLocale::​~QLocale()

Destructor

QString QLocale::​amText() const

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

This function was introduced in Qt 4.5.

See also pmText().

QString QLocale::​bcp47Name() const

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

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

This function tries to conform the locale name to BCP47.

This function was introduced in Qt 4.8.

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

[static] QLocale QLocale::​c()

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

See also system().

Country QLocale::​country() const

Returns the country of this locale.

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

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

Returns a QString containing the name of country.

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

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

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

This function was introduced in Qt 4.8.

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

Returns a currency symbol according to the format.

This function was introduced in Qt 4.8.

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

Returns the date format used for the current locale.

If format is LongFormat the format will be a long version. Otherwise it uses a shorter version.

This function was introduced in Qt 4.1.

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

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

Returns the date time format used for the current locale.

If format is ShortFormat the format will be a short version. Otherwise it uses a longer version.

This function was introduced in Qt 4.4.

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

QString QLocale::​dayName(int day, 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.

This function was introduced in Qt 4.2.

See also monthName() and standaloneDayName().

QChar QLocale::​decimalPoint() const

Returns the decimal point character of this locale.

This function was introduced in Qt 4.1.

QChar QLocale::​exponential() const

Returns the exponential character of this locale.

This function was introduced in Qt 4.1.

Qt::DayOfWeek QLocale::​firstDayOfWeek() const

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

This function was introduced in Qt 4.8.

QChar QLocale::​groupSeparator() const

Returns the group separator character of this locale.

This function was introduced in Qt 4.1.

Language QLocale::​language() const

Returns the language of this locale.

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

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

Returns a QString containing the name of language.

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

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

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

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

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

This function was introduced in Qt 4.8.

MeasurementSystem QLocale::​measurementSystem() const

Returns the measurement system for the locale.

This function was introduced in Qt 4.4.

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

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

This function was introduced in Qt 4.2.

See also dayName() and standaloneMonthName().

QString QLocale::​name() const

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

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

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

QString QLocale::​nativeCountryName() const

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

This function was introduced in Qt 4.8.

See also nativeLanguageName() and countryToString().

QString QLocale::​nativeLanguageName() const

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

This function was introduced in Qt 4.8.

See also nativeCountryName() and languageToString().

QChar QLocale::​negativeSign() const

Returns the negative sign character of this locale.

This function was introduced in Qt 4.1.

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.

This function was introduced in Qt 4.2.

See also setNumberOptions().

QChar QLocale::​percent() const

Returns the percent character of this locale.

This function was introduced in Qt 4.1.

QString QLocale::​pmText() const

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

This function was introduced in Qt 4.5.

See also amText().

QChar QLocale::​positiveSign() const

Returns the positive sign character of this locale.

This function was introduced in Qt 4.5.

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

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

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

Script QLocale::​script() const

Returns the script of this locale.

This function was introduced in Qt 4.8.

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

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

Returns a QString containing the name of script.

This function was introduced in Qt 4.8.

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

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

Sets the global default locale to locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used.

Warning: In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.

Warning: This function is not reentrant.

See also system() and c().

void QLocale::​setNumberOptions(NumberOptions options)

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

This function was introduced in Qt 4.2.

See also numberOptions().

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

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

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

This function was introduced in Qt 4.5.

See also dayName() and standaloneMonthName().

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

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

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

This function was introduced in Qt 4.5.

See also monthName() and standaloneDayName().

[static] QLocale QLocale::​system()

Returns a QLocale object initialized to the system locale.

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

See also c().

Qt::LayoutDirection QLocale::​textDirection() const

Returns the text direction of the language.

This function was introduced in Qt 4.7.

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

Returns the time format used for the current locale.

If format is LongFormat the format will be a long version. Otherwise it uses a shorter version.

This function was introduced in Qt 4.1.

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

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

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

This function was introduced in Qt 4.8.

See also currencySymbol().

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

This function was introduced in Qt 4.8.

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

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

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

This function was introduced in Qt 4.4.

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

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

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

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

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

This function was introduced in Qt 4.4.

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

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

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

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

This function was introduced in Qt 4.4.

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

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

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

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

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

This function was introduced in Qt 4.4.

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

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

Returns the double represented by the localized string s, or 0.0 if the conversion failed.

If ok is not 0, reports failure 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( "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

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 = german.toDouble( "1.234", &ok );    // ok == true, d == 1234.0

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

This function ignores leading and trailing whitespace.

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

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

Returns the double represented by the localized string s, or 0.0 if the conversion failed.

If ok is not null, reports failure 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( "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

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 = german.toDouble( "1.234", &ok );    // ok == true, d == 1234.0

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

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

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

Returns the float represented by the localized string s, or 0.0 if the conversion failed.

If ok is not 0, reports failure 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 QStringRef & s, bool * ok = 0) const

Returns the float represented by the localized string s, or 0.0 if the conversion failed.

If ok is not null, reports failure by setting *ok to false and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

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

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

Returns the int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toUInt() and toString().

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

Returns the int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toUInt() and toString().

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

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

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

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

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

Returns a lowercase copy of str.

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

This function was introduced in Qt 4.8.

See also QString::toLower().

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

Returns the short int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toUShort() and toString().

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

Returns the short int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toUShort() and toString().

QString QLocale::​toString(qlonglong i) const

Returns a localized string representation of i.

See also toLongLong().

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

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

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

Returns a localized string representation of the given date according to the specified format.

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

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

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

Returns a localized string representation of the given time in the specified format.

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

Returns a localized string representation of the given dateTime according to the specified format.

This function was introduced in Qt 4.4.

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

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

This function was introduced in Qt 4.4.

QString QLocale::​toString(qulonglong i) const

This is an overloaded function.

See also toULongLong().

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

This is an overloaded function.

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

See also toDouble().

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(float i, char f = 'g', int prec = 6) const

This is an overloaded function.

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

See also toDouble().

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

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

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

This function was introduced in Qt 4.4.

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

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

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

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

This function was introduced in Qt 4.4.

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

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

Returns the unsigned int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toInt() and toString().

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

Returns the unsigned int represented by the localized string s.

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toInt() and toString().

qulonglong QLocale::​toULongLong(const QString & s, bool * ok = 0) 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 0, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

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

qulonglong QLocale::​toULongLong(const QStringRef & s, bool * ok = 0) 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 null, failure is reported by setting *ok to false, and success by setting *ok to true.

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

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

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

See also toShort() and toString().

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

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

If the conversion fails the function returns 0.

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

This function ignores leading and trailing whitespace.

This function was introduced in Qt 5.1.

See also toShort() and toString().

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.

This function was introduced in Qt 4.8.

See also QString::toUpper().

QStringList QLocale::​uiLanguages() const

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

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

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

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

This function was introduced in Qt 4.8.

See also QTranslator and bcp47Name().

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

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

This function was introduced in Qt 4.8.

QChar QLocale::​zeroDigit() const

Returns the zero digit character of this locale.

This function was introduced in Qt 4.1.

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

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

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

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

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

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

© 2015 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.