QLocale Class Reference |
class | Data |
enum | Country { AnyCountry, Afghanistan, Albania, Algeria, ..., Zimbabwe } |
enum | FormatType { LongFormat, ShortFormat, NarrowFormat } |
enum | Language { C, Abkhazian, Afan, Afar, ..., Chewa } |
enum | MeasurementSystem { MetricSystem, ImperialSystem } |
enum | NumberOption { OmitGroupSeparator, RejectGroupSeparator } |
flags | NumberOptions |
QLocale () | |
QLocale ( const QString & name ) | |
QLocale ( Language language, Country country = AnyCountry ) | |
QLocale ( const QLocale & other ) | |
QString | amText () const |
Country | country () 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 |
QChar | groupSeparator () const |
Language | language () const |
MeasurementSystem | measurementSystem () const |
QString | monthName ( int month, FormatType type = LongFormat ) const |
QString | name () const |
QChar | negativeSign () const |
NumberOptions | numberOptions () const |
QChar | percent () const |
QString | pmText () const |
QChar | positiveSign () const |
void | setNumberOptions ( NumberOptions options ) |
QString | standaloneDayName ( int day, FormatType type = LongFormat ) const |
QString | standaloneMonthName ( int month, FormatType type = LongFormat ) const |
QString | timeFormat ( FormatType format = LongFormat ) 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 |
float | toFloat ( const QString & s, bool * ok = 0 ) const |
int | toInt ( const QString & s, bool * ok = 0, int base = 0 ) const |
qlonglong | toLongLong ( const QString & s, bool * ok = 0, int base = 0 ) const |
short | toShort ( const QString & s, bool * ok = 0, int base = 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, int base = 0 ) const |
qlonglong | toULongLong ( const QString & s, bool * ok = 0, int base = 0 ) const |
ushort | toUShort ( const QString & s, bool * ok = 0, int base = 0 ) const |
QChar | zeroDigit () const |
bool | operator!= ( const QLocale & other ) const |
QLocale & | operator= ( const QLocale & other ) |
bool | operator== ( const QLocale & other ) const |
QLocale | c () |
QList<Country> | countriesForLanguage ( Language language ) |
QString | countryToString ( Country country ) |
QString | languageToString ( Language language ) |
void | setDefault ( const QLocale & locale ) |
QLocale | system () |
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:
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:
The "C" locale is identical in behavior 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.
QLocale's data is based on Common Locale Data Repository v1.6.1.
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(), and QString::toDouble().