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 simmilar to those in QString.
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:
If a QLocale object is constructed with the default constructor,
it will use the default locale's settings.
QString::toDouble() interprets 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".
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()).
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.
Member Type Documentation
QLocale::Country
This enumerated type is used to specify a country.
QLocale::AnyCountry
QLocale::Afghanistan
QLocale::Albania
QLocale::Algeria
QLocale::AmericanSamoa
QLocale::Andorra
QLocale::Angola
QLocale::Anguilla
QLocale::Antarctica
QLocale::AntiguaAndBarbuda
QLocale::Argentina
QLocale::Armenia
QLocale::Aruba
QLocale::Australia
QLocale::Austria
QLocale::Azerbaijan
QLocale::Bahamas
QLocale::Bahrain
QLocale::Bangladesh
QLocale::Barbados
QLocale::Belarus
QLocale::Belgium
QLocale::Belize
QLocale::Benin
QLocale::Bermuda
QLocale::Bhutan
QLocale::Bolivia
QLocale::BosniaAndHerzegowina
QLocale::Botswana
QLocale::BouvetIsland
QLocale::Brazil
QLocale::BritishIndianOceanTerritory
QLocale::BruneiDarussalam
QLocale::Bulgaria
QLocale::BurkinaFaso
QLocale::Burundi
QLocale::Cambodia
QLocale::Cameroon
QLocale::Canada
QLocale::CapeVerde
QLocale::CaymanIslands
QLocale::CentralAfricanRepublic
QLocale::Chad
QLocale::Chile
QLocale::China
QLocale::ChristmasIsland
QLocale::CocosIslands
QLocale::Colombia
QLocale::Comoros
QLocale::DemocraticRepublicOfCongo
QLocale::PeoplesRepublicOfCongo
QLocale::CookIslands
QLocale::CostaRica
QLocale::IvoryCoast
QLocale::Croatia
QLocale::Cuba
QLocale::Cyprus
QLocale::CzechRepublic
QLocale::Denmark
QLocale::Djibouti
QLocale::Dominica
QLocale::DominicanRepublic
QLocale::EastTimor
QLocale::Ecuador
QLocale::Egypt
QLocale::ElSalvador
QLocale::EquatorialGuinea
QLocale::Eritrea
QLocale::Estonia
QLocale::Ethiopia
QLocale::FalklandIslands
QLocale::FaroeIslands
QLocale::FijiCountry
QLocale::Finland
QLocale::France
QLocale::MetropolitanFrance
QLocale::FrenchGuiana
QLocale::FrenchPolynesia
QLocale::FrenchSouthernTerritories
QLocale::Gabon
QLocale::Gambia
QLocale::Georgia
QLocale::Germany
QLocale::Ghana
QLocale::Gibraltar
QLocale::Greece
QLocale::Greenland
QLocale::Grenada
QLocale::Guadeloupe
QLocale::Guam
QLocale::Guatemala
QLocale::Guinea
QLocale::GuineaBissau
QLocale::Guyana
QLocale::Haiti
QLocale::HeardAndMcDonaldIslands
QLocale::Honduras
QLocale::HongKong
QLocale::Hungary
QLocale::Iceland
QLocale::India
QLocale::Indonesia
QLocale::Iran
QLocale::Iraq
QLocale::Ireland
QLocale::Israel
QLocale::Italy
QLocale::Jamaica
QLocale::Japan
QLocale::Jordan
QLocale::Kazakhstan
QLocale::Kenya
QLocale::Kiribati
QLocale::DemocraticRepublicOfKorea
QLocale::RepublicOfKorea
QLocale::Kuwait
QLocale::Kyrgyzstan
QLocale::Lao
QLocale::Latvia
QLocale::Lebanon
QLocale::Lesotho
QLocale::Liberia
QLocale::LibyanArabJamahiriya
QLocale::Liechtenstein
QLocale::Lithuania
QLocale::Luxembourg
QLocale::Macau
QLocale::Macedonia
QLocale::Madagascar
QLocale::Malawi
QLocale::Malaysia
QLocale::Maldives
QLocale::Mali
QLocale::Malta
QLocale::MarshallIslands
QLocale::Martinique
QLocale::Mauritania
QLocale::Mauritius
QLocale::Mayotte
QLocale::Mexico
QLocale::Micronesia
QLocale::Moldova
QLocale::Monaco
QLocale::Mongolia
QLocale::Montserrat
QLocale::Morocco
QLocale::Mozambique
QLocale::Myanmar
QLocale::Namibia
QLocale::NauruCountry
QLocale::Nepal
QLocale::Netherlands
QLocale::NetherlandsAntilles
QLocale::NewCaledonia
QLocale::NewZealand
QLocale::Nicaragua
QLocale::Niger
QLocale::Nigeria
QLocale::Niue
QLocale::NorfolkIsland
QLocale::NorthernMarianaIslands
QLocale::Norway
QLocale::Oman
QLocale::Pakistan
QLocale::Palau
QLocale::PalestinianTerritory
QLocale::Panama
QLocale::PapuaNewGuinea
QLocale::Paraguay
QLocale::Peru
QLocale::Philippines
QLocale::Pitcairn
QLocale::Poland
QLocale::Portugal
QLocale::PuertoRico
QLocale::Qatar
QLocale::Reunion
QLocale::Romania
QLocale::RussianFederation
QLocale::Rwanda
QLocale::SaintKittsAndNevis
QLocale::StLucia
QLocale::StVincentAndTheGrenadines
QLocale::Samoa
QLocale::SanMarino
QLocale::SaoTomeAndPrincipe
QLocale::SaudiArabia
QLocale::Senegal
QLocale::Seychelles
QLocale::SierraLeone
QLocale::Singapore
QLocale::Slovakia
QLocale::Slovenia
QLocale::SolomonIslands
QLocale::Somalia
QLocale::SouthAfrica
QLocale::SouthGeorgiaAndTheSouthSandwichIslands
QLocale::Spain
QLocale::SriLanka
QLocale::StHelena
QLocale::StPierreAndMiquelon
QLocale::Sudan
QLocale::Suriname
QLocale::SvalbardAndJanMayenIslands
QLocale::Swaziland
QLocale::Sweden
QLocale::Switzerland
QLocale::SyrianArabRepublic
QLocale::Taiwan
QLocale::Tajikistan
QLocale::Tanzania
QLocale::Thailand
QLocale::Togo
QLocale::Tokelau
QLocale::TongaCountry
QLocale::TrinidadAndTobago
QLocale::Tunisia
QLocale::Turkey
QLocale::Turkmenistan
QLocale::TurksAndCaicosIslands
QLocale::Tuvalu
QLocale::Uganda
QLocale::Ukraine
QLocale::UnitedArabEmirates
QLocale::UnitedKingdom
QLocale::UnitedStates
QLocale::UnitedStatesMinorOutlyingIslands
QLocale::Uruguay
QLocale::Uzbekistan
QLocale::Vanuatu
QLocale::VaticanCityState
QLocale::Venezuela
QLocale::VietNam
QLocale::BritishVirginIslands
QLocale::USVirginIslands
QLocale::WallisAndFutunaIslands
QLocale::WesternSahara
QLocale::Yemen
QLocale::Yugoslavia
QLocale::Zambia
QLocale::Zimbabwe
QLocale::Language
This enumerated type is used to specify a language.
QLocale::C - Identical to English/UnitedStates
QLocale::Abkhazian
QLocale::Afan
QLocale::Afar
QLocale::Afrikaans
QLocale::Albanian
QLocale::Amharic
QLocale::Arabic
QLocale::Armenian
QLocale::Assamese
QLocale::Aymara
QLocale::Azerbaijani
QLocale::Bashkir
QLocale::Basque
QLocale::Bengali
QLocale::Bhutani
QLocale::Bihari
QLocale::Bislama
QLocale::Breton
QLocale::Bulgarian
QLocale::Burmese
QLocale::Byelorussian
QLocale::Cambodian
QLocale::Catalan
QLocale::Chinese
QLocale::Corsican
QLocale::Croatian
QLocale::Czech
QLocale::Danish
QLocale::Dutch
QLocale::English
QLocale::Esperanto
QLocale::Estonian
QLocale::Faroese
QLocale::FijiLanguage
QLocale::Finnish
QLocale::French
QLocale::Frisian
QLocale::Gaelic
QLocale::Galician
QLocale::Georgian
QLocale::German
QLocale::Greek
QLocale::Greenlandic
QLocale::Guarani
QLocale::Gujarati
QLocale::Hausa
QLocale::Hebrew
QLocale::Hindi
QLocale::Hungarian
QLocale::Icelandic
QLocale::Indonesian
QLocale::Interlingua
QLocale::Interlingue
QLocale::Inuktitut
QLocale::Inupiak
QLocale::Irish
QLocale::Italian
QLocale::Japanese
QLocale::Javanese
QLocale::Kannada
QLocale::Kashmiri
QLocale::Kazakh
QLocale::Kinyarwanda
QLocale::Kirghiz
QLocale::Korean
QLocale::Kurdish
QLocale::Kurundi
QLocale::Laothian
QLocale::Latin
QLocale::Latvian
QLocale::Lingala
QLocale::Lithuanian
QLocale::Macedonian
QLocale::Malagasy
QLocale::Malay
QLocale::Malayalam
QLocale::Maltese
QLocale::Maori
QLocale::Marathi
QLocale::Moldavian
QLocale::Mongolian
QLocale::NauruLanguage
QLocale::Nepali
QLocale::Norwegian
QLocale::Occitan
QLocale::Oriya
QLocale::Pashto
QLocale::Persian
QLocale::Polish
QLocale::Portuguese
QLocale::Punjabi
QLocale::Quechua
QLocale::RhaetoRomance
QLocale::Romanian
QLocale::Russian
QLocale::Samoan
QLocale::Sangho
QLocale::Sanskrit
QLocale::Serbian
QLocale::SerboCroatian
QLocale::Sesotho
QLocale::Setswana
QLocale::Shona
QLocale::Sindhi
QLocale::Singhalese
QLocale::Siswati
QLocale::Slovak
QLocale::Slovenian
QLocale::Somali
QLocale::Spanish
QLocale::Sundanese
QLocale::Swahili
QLocale::Swedish
QLocale::Tagalog
QLocale::Tajik
QLocale::Tamil
QLocale::Tatar
QLocale::Telugu
QLocale::Thai
QLocale::Tibetan
QLocale::Tigrinya
QLocale::TongaLanguage
QLocale::Tsonga
QLocale::Turkish
QLocale::Turkmen
QLocale::Twi
QLocale::Uigur
QLocale::Ukrainian
QLocale::Urdu
QLocale::Uzbek
QLocale::Vietnamese
QLocale::Volapuk
QLocale::Welsh
QLocale::Wolof
QLocale::Xhosa
QLocale::Yiddish
QLocale::Yoruba
QLocale::Zhuang
QLocale::Zulu
Member Function Documentation
QLocale::QLocale ()
Constructs a QLocale object initialized with the default locale.
Constructs a QLocale object with the specified name,
which has the format
"language[_country][.codeset][@modifier]" or "C", where:
language is a lowercase, two-letter, ISO 639 language code,
territory is an uppercase, two-letter, ISO 3166 country code,
and codeset and modifier are ignored.
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).
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().
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.
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.
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.
Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.
Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).
Qt dans le magazine
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter
ou par MP !