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

Almost all the functions in this class are reentrant when Qt is built with thread support. The exception is setDefaultLocale().

#include <qlocale.h>

List of all member functions.

Public Members

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 simmilar 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);
    

Additionally, QLocale supports the concept of a default locale, which can be set with the static member setDefaultLocale(). This allows a locale to be set globally for the entire application.

    QLocale::setDefaultLocale(QLocale::German, QLocale::Switzerland);

    QLocale swiss; // Constructor parameters default to DefaultLanguage/DefaultCountry
    QString s1 = swiss.toString(15714.3, 'e');
    

When a language/country pair is specified in the constructor, one of four 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 Unix locale name.

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

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

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

See also Text Related Classes.


Member Type Documentation

QLocale::Country

This enumerated type is used to specify a country.

QLocale::Language

This enumerated type is used to specify a language.


Member Function Documentation

QLocale::QLocale ( const QString & unixLocale )

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

If the string violates the Unix 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 unixLocaleName().

QLocale::QLocale ( Language language = DefaultLanguage, Country country = DefaultCountry )

Constructs a QLocale object with the specified language and country. If language is DefaultLanguage and country is DefaultCountry, the values set with setDefaultLocale() are used, or if setDefaultLocale() has not been called the "C" locale is used.

QLocale might use different language/country values than specified in the constructor, depending on what's available in the database. The language and country that are actually used can be queried using language() and country().

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

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.

void QLocale::setDefaultLocale ( Language language = DefaultLanguage, Country country = DefaultCountry ) [static]

Warning: This function is not reentrant.

Sets the global default locale to language and country. These values are used when a QLocale object is constructed with DefaultLanguage and DefaultCountry.

Warning: This method is not reentrant. The default locale should be set at application startup, before any new threads are created.

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

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.

See also 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.

See also toString().

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

Returns the int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

Q_LONG QLocale::toLong ( const QString & s, bool * ok = 0 ) const

Returns the long int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

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

Returns the long long int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

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

Returns the short int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

QString QLocale::toString ( Q_LLONG i ) const

Returns a localized string representation of i.

See also toLongLong().

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

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

See also toLong().

QString QLocale::toString ( Q_ULONG i ) const

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

See also toULong().

QString QLocale::toString ( Q_ULLONG i ) const

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

See also toULongLong().

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

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

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

Returns the unsigned int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

Q_ULONG QLocale::toULong ( const QString & s, bool * ok = 0 ) const

Returns the unsigned long int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

Q_ULLONG QLocale::toULongLong ( const QString & s, bool * ok = 0 ) const

Returns the unsigned long long int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

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

Returns the unsigned short int represented by the localized string s, or 0 if the conversion failed.

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

See also toString().

QString QLocale::unixLocaleName () const

Returns the language and country of this locale as a Unix locale 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().


This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.


Copyright © 2003 TrolltechTrademarks
Qt 3.3.0b1