Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions

QLocale Class Reference

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

#include <QLocale>

Part of the QtCore module.

Note: All the functions in this class are reentrant, except setDefault().

Public Types

Public Functions

Static Public Members


Detailed Description

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

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

    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 s2 = 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(). The default locale has the following effects:

    QLocale::setDefault(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::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:

The "C" locale is identical to English/UnitedStates.

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.

All the methods in QLocale, with the exception of setDefault(), are reentrant.

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::toDouble() and QString::arg().


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::BruneiDarussalam32 
QLocale::Bulgaria33 
QLocale::BurkinaFaso34 
QLocale::Burundi35 
QLocale::Cambodia36 
QLocale::Cameroon37 
QLocale::Canada38 
QLocale::CapeVerde39 
QLocale::CaymanIslands40 
QLocale::CentralAfricanRepublic41 
QLocale::Chad42 
QLocale::Chile43 
QLocale::China44 
QLocale::ChristmasIsland45 
QLocale::CocosIslands46 
QLocale::Colombia47 
QLocale::Comoros48 
QLocale::DemocraticRepublicOfCongo49 
QLocale::PeoplesRepublicOfCongo50 
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::FijiCountry72 
QLocale::Finland73 
QLocale::France74 
QLocale::MetropolitanFrance75 
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::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::DemocraticRepublicOfKorea113 
QLocale::RepublicOfKorea114 
QLocale::Kuwait115 
QLocale::Kyrgyzstan116 
QLocale::Lao117 
QLocale::Latvia118 
QLocale::Lebanon119 
QLocale::Lesotho120 
QLocale::Liberia121 
QLocale::LibyanArabJamahiriya122 
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::NetherlandsAntilles152 
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::PalestinianTerritory165 
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::RussianFederation178 
QLocale::Rwanda179 
QLocale::SaintKittsAndNevis180 
QLocale::StLucia181 
QLocale::StVincentAndTheGrenadines182 
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::StHelena199 
QLocale::StPierreAndMiquelon200 
QLocale::Sudan201 
QLocale::Suriname202 
QLocale::SvalbardAndJanMayenIslands203 
QLocale::Swaziland204 
QLocale::Sweden205 
QLocale::Switzerland206 
QLocale::SyrianArabRepublic207 
QLocale::Taiwan208 
QLocale::Tajikistan209 
QLocale::Tanzania210 
QLocale::Thailand211 
QLocale::Togo212 
QLocale::Tokelau213 
QLocale::TongaCountry214 
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::USVirginIslands234 
QLocale::WallisAndFutunaIslands235 
QLocale::WesternSahara236 
QLocale::Yemen237 
QLocale::Yugoslavia238 
QLocale::Zambia239 
QLocale::Zimbabwe240

enum QLocale::Language

This enumerated type is used to specify a language.

ConstantValueDescription
QLocale::C1Identical to English/UnitedStates
QLocale::Abkhazian2 
QLocale::Afan3 
QLocale::Afar4 
QLocale::Afrikaans5 
QLocale::Albanian6 
QLocale::Amharic7 
QLocale::Arabic8 
QLocale::Armenian9 
QLocale::Assamese10 
QLocale::Aymara11 
QLocale::Azerbaijani12 
QLocale::Bashkir13 
QLocale::Basque14 
QLocale::Bengali15 
QLocale::Bhutani16 
QLocale::Bihari17 
QLocale::Bislama18 
QLocale::Breton19 
QLocale::Bulgarian20 
QLocale::Burmese21 
QLocale::Byelorussian22 
QLocale::Cambodian23 
QLocale::Catalan24 
QLocale::Chinese25 
QLocale::Corsican26 
QLocale::Croatian27 
QLocale::Czech28 
QLocale::Danish29 
QLocale::Dutch30 
QLocale::English31 
QLocale::Esperanto32 
QLocale::Estonian33 
QLocale::Faroese34 
QLocale::FijiLanguage35 
QLocale::Finnish36 
QLocale::French37 
QLocale::Frisian38 
QLocale::Gaelic39 
QLocale::Galician40 
QLocale::Georgian41 
QLocale::German42 
QLocale::Greek43 
QLocale::Greenlandic44 
QLocale::Guarani45 
QLocale::Gujarati46 
QLocale::Hausa47 
QLocale::Hebrew48 
QLocale::Hindi49 
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::Kashmiri62 
QLocale::Kazakh63 
QLocale::Kinyarwanda64 
QLocale::Kirghiz65 
QLocale::Korean66 
QLocale::Kurdish67 
QLocale::Kurundi68 
QLocale::Laothian69 
QLocale::Latin70 
QLocale::Latvian71 
QLocale::Lingala72 
QLocale::Lithuanian73 
QLocale::Macedonian74 
QLocale::Malagasy75 
QLocale::Malay76 
QLocale::Malayalam77 
QLocale::Maltese78 
QLocale::Maori79 
QLocale::Marathi80 
QLocale::Moldavian81 
QLocale::Mongolian82 
QLocale::NauruLanguage83 
QLocale::Nepali84 
QLocale::Norwegian85 
QLocale::Nynorsk141 
QLocale::Occitan86 
QLocale::Oriya87 
QLocale::Pashto88 
QLocale::Persian89 
QLocale::Polish90 
QLocale::Portuguese91 
QLocale::Punjabi92 
QLocale::Quechua93 
QLocale::RhaetoRomance94 
QLocale::Romanian95 
QLocale::Russian96 
QLocale::Samoan97 
QLocale::Sangho98 
QLocale::Sanskrit99 
QLocale::Serbian100 
QLocale::SerboCroatian101 
QLocale::Sesotho102 
QLocale::Setswana103 
QLocale::Shona104 
QLocale::Sindhi105 
QLocale::Singhalese106 
QLocale::Siswati107 
QLocale::Slovak108 
QLocale::Slovenian109 
QLocale::Somali110 
QLocale::Spanish111 
QLocale::Sundanese112 
QLocale::Swahili113 
QLocale::Swedish114 
QLocale::Tagalog115 
QLocale::Tajik116 
QLocale::Tamil117 
QLocale::Tatar118 
QLocale::Telugu119 
QLocale::Thai120 
QLocale::Tibetan121 
QLocale::Tigrinya122 
QLocale::TongaLanguage123 
QLocale::Tsonga124 
QLocale::Turkish125 
QLocale::Turkmen126 
QLocale::Twi127 
QLocale::Uigur128 
QLocale::Ukrainian129 
QLocale::Urdu130 
QLocale::Uzbek131 
QLocale::Vietnamese132 
QLocale::Volapuk133 
QLocale::Welsh134 
QLocale::Wolof135 
QLocale::Xhosa136 
QLocale::Yiddish137 
QLocale::Yoruba138 
QLocale::Zhuang139 
QLocale::Zulu140

Member Function Documentation

QLocale::QLocale ()

Constructs a QLocale object initialized with the default locale.

See also setDefault().

QLocale::QLocale ( const QString & name )

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

If the string violates the locale format, or language is not a valid ISO 369 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 and country codes are converted to their respective Language and Country enums. After this conversion is performed the constructor behaves exactly like QLocale(Country, Language).

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

See also name().

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

Constructs a QLocale object with the specified language and country.

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

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

QLocale::QLocale ( const QLocale & other )

Constructs a QLocale object as a copy of other.

QLocale QLocale::c ()   [static]

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

See also system().

Country QLocale::country () const

Returns the country of this locale.

See also QLocale().

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

Returns a QString containing the name of country.

Language QLocale::language () const

Returns the language of this locale.

See also QLocale().

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

Returns a QString containing the name of language.

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-letter ISO 3166 country code.

See also QLocale().

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

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

QLocale QLocale::system ()   [static]

Returns a QLocale object initialized to the system locale.

See also QTextCodec::locale() and c().

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 toString() and QString::toDouble().

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

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

Returns the int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

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

Returns the long long int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

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

Returns the short int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

QString QLocale::toString ( qlonglong i ) const

QString QLocale::toString ( qulonglong i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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 member function, provided for convenience. It behaves essentially like the above function.

See also toShort().

QString QLocale::toString ( ushort i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toUShort().

QString QLocale::toString ( int i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toInt().

QString QLocale::toString ( uint i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toUInt().

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

See also toDouble().

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

Returns the unsigned int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

qlonglong QLocale::toULongLong ( const QString & s, bool * ok = 0, int base = 0 ) const

Returns the unsigned long long int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

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

Returns the unsigned short int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

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

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

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

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.


Copyright © 2005 Trolltech Trademarks
Qt 4.0.0-b2