QLocale 类

QLocale 类在各种语言的数字及其字符串表示之间转换。 更多...

头: #include <QLocale>
CMake: find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

注意: 此类的所有函数 可重入 除以下外:

公共类型

enum Country { AnyCountry, AnyTerritory, Afghanistan, AlandIslands, Albania, …, Zimbabwe }
enum CurrencySymbolFormat { CurrencyIsoCode, CurrencySymbol, CurrencyDisplayName }
enum DataSizeFormat { DataSizeIecFormat, DataSizeTraditionalFormat, DataSizeSIFormat }
flags DataSizeFormats
enum FloatingPointPrecisionOption { FloatingPointShortest }
enum FormatType { LongFormat, ShortFormat, NarrowFormat }
enum Language { AnyLanguage, C, Abkhazian, Afan, Afar, …, Zulu }
enum MeasurementSystem { MetricSystem, ImperialUSSystem, ImperialUKSystem, ImperialSystem }
enum NumberOption { DefaultNumberOptions, OmitGroupSeparator, RejectGroupSeparator, OmitLeadingZeroInExponent, RejectLeadingZeroInExponent, …, RejectTrailingZeroesAfterDot }
flags NumberOptions
enum QuotationStyle { StandardQuotation, AlternateQuotation }
enum Script { AnyScript, AdlamScript, AhomScript, AnatolianHieroglyphsScript, ArabicScript, …, YiScript }
  Territory

公共函数

  QLocale (const QLocale & other )
  QLocale (QLocale::Language language , QLocale::Script script = AnyScript, QLocale::Territory territory = AnyTerritory)
  QLocale (QLocale::Language language , QLocale::Territory territory )
  QLocale (const QString & name )
  QLocale ()
QLocale & operator= (const QLocale & other )
  ~QLocale ()
QString amText () const
QString bcp47Name () const
QLocale collation () const
QString createSeparatedList (const QStringList & list ) const
QString currencySymbol (QLocale::CurrencySymbolFormat format = CurrencySymbol) const
QString dateFormat (QLocale::FormatType format = LongFormat) const
QString dateTimeFormat (QLocale::FormatType format = LongFormat) const
QString dayName (int day , QLocale::FormatType type = LongFormat) const
QString decimalPoint () const
QString exponential () const
Qt::DayOfWeek firstDayOfWeek () const
QString formattedDataSize (qint64 bytes , int precision = 2, QLocale::DataSizeFormats format = DataSizeIecFormat) const
QString groupSeparator () const
QLocale::Language language () const
QLocale::MeasurementSystem measurementSystem () const
QString monthName (int month , QLocale::FormatType type = LongFormat) const
QString name () const
QString nativeLanguageName () const
QString nativeTerritoryName () const
QString negativeSign () const
QLocale::NumberOptions numberOptions () const
QString percent () const
QString pmText () const
QString positiveSign () const
QString quoteString (const QString & str , QLocale::QuotationStyle style = StandardQuotation) const
QString quoteString (QStringView str , QLocale::QuotationStyle style = StandardQuotation) const
QLocale::Script script () const
void setNumberOptions (QLocale::NumberOptions options )
QString standaloneDayName (int day , QLocale::FormatType type = LongFormat) const
QString standaloneMonthName (int month , QLocale::FormatType type = LongFormat) const
void swap (QLocale & other )
QLocale::Territory territory () const
Qt::LayoutDirection textDirection () const
QString timeFormat (QLocale::FormatType format = LongFormat) const
QString toCurrencyString (qlonglong value , const QString & symbol = QString()) const
QString toCurrencyString (qulonglong 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 (double value , const QString & symbol = QString(), int precision = -1) const
QString toCurrencyString (float i , const QString & symbol = QString(), int precision = -1) const
QDate toDate (const QString & string , QLocale::FormatType format = LongFormat) const
QDate toDate (const QString & string , const QString & format ) const
QDate toDate (const QString & string , QLocale::FormatType format , QCalendar cal ) const
QDate toDate (const QString & string , const QString & format , QCalendar cal ) const
QDateTime toDateTime (const QString & string , QLocale::FormatType format = LongFormat) const
QDateTime toDateTime (const QString & string , const QString & format ) const
QDateTime toDateTime (const QString & string , QLocale::FormatType format , QCalendar cal ) const
QDateTime toDateTime (const QString & string , const QString & format , QCalendar cal ) const
double toDouble (const QString & s , bool * ok = nullptr) const
double toDouble (QStringView s , bool * ok = nullptr) const
float toFloat (const QString & s , bool * ok = nullptr) const
float toFloat (QStringView s , bool * ok = nullptr) const
int toInt (const QString & s , bool * ok = nullptr) const
int toInt (QStringView s , bool * ok = nullptr) const
long toLong (const QString & s , bool * ok = nullptr) const
long toLong (QStringView s , bool * ok = nullptr) const
qlonglong toLongLong (const QString & s , bool * ok = nullptr) const
qlonglong toLongLong (QStringView s , bool * ok = nullptr) const
QString toLower (const QString & str ) const
short toShort (const QString & s , bool * ok = nullptr) const
short toShort (QStringView s , bool * ok = nullptr) const
QString toString (qlonglong i ) const
QString toString (qulonglong i ) const
QString toString (long i ) const
QString toString (ulong i ) const
QString toString (short i ) const
QString toString (ushort i ) const
QString toString (int i ) const
QString toString (uint i ) const
QString toString (double f , char format = 'g', int precision = 6) const
QString toString (float f , char format = 'g', int precision = 6) const
QString toString (QDate date , const QString & format ) const
QString toString (QTime time , const QString & format ) const
QString toString (const QDateTime & dateTime , const QString & format ) const
QString toString (QDate date , QStringView format ) const
QString toString (QTime time , QStringView format ) const
QString toString (const QDateTime & dateTime , QStringView format ) const
QString toString (QDate date , QLocale::FormatType format = LongFormat) const
QString toString (QTime time , QLocale::FormatType format = LongFormat) const
QString toString (const QDateTime & dateTime , QLocale::FormatType format = LongFormat) const
QString toString (QDate date , QStringView format , QCalendar cal ) const
QString toString (QDate date , QLocale::FormatType format , QCalendar cal ) const
QString toString (const QDateTime & dateTime , QLocale::FormatType format , QCalendar cal ) const
QString toString (const QDateTime & dateTime , QStringView format , QCalendar cal ) const
QTime toTime (const QString & string , QLocale::FormatType format = LongFormat) const
QTime toTime (const QString & string , const QString & format ) const
uint toUInt (const QString & s , bool * ok = nullptr) const
uint toUInt (QStringView s , bool * ok = nullptr) const
ulong toULong (const QString & s , bool * ok = nullptr) const
ulong toULong (QStringView s , bool * ok = nullptr) const
qulonglong toULongLong (const QString & s , bool * ok = nullptr) const
qulonglong toULongLong (QStringView s , bool * ok = nullptr) const
ushort toUShort (const QString & s , bool * ok = nullptr) const
ushort toUShort (QStringView s , bool * ok = nullptr) const
QString toUpper (const QString & str ) const
QStringList uiLanguages () const
QList<Qt::DayOfWeek> weekdays () const
QString zeroDigit () const

静态公共成员

QLocale c ()
QLocale::Language codeToLanguage (QStringView languageCode )
QLocale::Script codeToScript (QStringView scriptCode )
QLocale::Territory codeToTerritory (QStringView territoryCode )
QString languageToCode (QLocale::Language language )
QString languageToString (QLocale::Language language )
QList<QLocale> matchingLocales (QLocale::Language language , QLocale::Script script , QLocale::Territory territory )
QString scriptToCode (QLocale::Script script )
QString scriptToString (QLocale::Script script )
void setDefault (const QLocale & locale )
QLocale system ()
QString territoryToCode (QLocale::Territory territory )
QString territoryToString (QLocale::Territory territory )
size_t qHash (const QLocale & key , size_t seed = 0)
bool operator!= (const QLocale & lhs , const QLocale & rhs )
bool operator== (const QLocale & lhs , const QLocale & rhs )

详细描述

QLocale 是为指定语言、可选脚本和地区构造的。它提供将数据格式化成文本、适当本地化及从本地化文本读取数据的各种设施。

范例:

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 支持默认区域设置概念,在应用程序启动时由系统区域设置确定。可以改变默认区域设置通过调用静态成员 setDefault ()。设置默认区域设置有下列影响:

  • 若 QLocale 对象是采用默认构造函数构造的,将使用默认区域设置。
  • QString::arg () 使用默认区域设置格式化数字,当它在格式化字符串中的位置说明符包含 L 时 (如:%L1)。

以下范例阐明如何直接使用 QLocale:

bool ok;
double d;
QLocale::setDefault(QLocale::C);      // uses '.' as a decimal point
QLocale cLocale;                      // default-constructed C locale
d = cLocale.toDouble("1234,56", &ok); // ok == false, d == 0
d = cLocale.toDouble("1234.56", &ok); // ok == true,  d == 1234.56
QLocale::setDefault(QLocale::German); // uses ',' as a decimal point
QLocale german;                       // default-constructed German locale
d = german.toDouble("1234,56", &ok);  // ok == true,  d == 1234.56
d = german.toDouble("1234.56", &ok);  // ok == false, d == 0
QLocale::setDefault(QLocale::English);
// Default locale now uses ',' as a group separator.
QString str = QString("%1 %L2 %L3").arg(12345).arg(12345).arg(12345, 0, 16);
// str == "12345 12,345 3039"
					

构造 QLocale 对象的替代方法是通过指定区域设置名称。

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

此构造函数从给定名称读取语言、脚本和/或地区,接受下划线或破折号作为分隔符(并忽略任何结尾 .codeset or @variant 后缀)。

注意: 对于当前键盘输入区域设置,请查看 QInputMethod::locale ().

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

语言、脚本和地区的匹配组合

QLocale 针对语言、脚本和地区的很多组合 (但不是全部) 拥有派生自 CLDR (公共区域设置数据存储库) 的数据。若它是采用所有这些的 3 指定键值构造的 (视 AnyLanguage , AnyScript or AnyTerritory 为未指定) 且 QLocale 拥有针对给定组合的数据,则使用该数据。否则,QLocale 会尽力找出语言、脚本和地区的合理组合,为拥有如这些指定的匹配数据。

CLDR 提供可能的组合表,用于填充一个或多个任何未指定键;若 QLocale 拥有针对这种可能组合的数据结果,将使用它。若语言未指定,且无法从脚本和地区确定,或者若 QLocale 不拥有语言数据,则使用 C (当从字符串读取键时) 或默认区域设置 (否则)。

当 QLocale 不拥有如指定键的数据,在未指定的地方以可能的键填充,但拥有如结果语言的数据,则基于地区、脚本或两者 (按此次序) 的忽略寻址回退。这会导致 QLocale 可能不匹配要求,但将为指定键提供可用准许数据的合适本地化。

使用 language (), script () 和 territory () 以确定实际使用键。

另请参阅 QString::arg () 和 QInputMethod::locale ().

成员类型文档编制

enum QLocale:: Country

此枚举类型用于标识地区。

单独地区可能是一个国家的省,国家 (目前为止的最常见情况) 或更大地理实体,其中某些本地化细节是特定的。

常量 描述
QLocale::AnyCountry AnyTerritory 过时别名对于 AnyTerritory
QLocale::AnyTerritory 0 Since 6.2
QLocale::Afghanistan 1
QLocale::AlandIslands 2
QLocale::Albania 3
QLocale::Algeria 4
QLocale::AmericanSamoa 5
QLocale::Andorra 6
QLocale::Angola 7
QLocale::Anguilla 8
QLocale::Antarctica 9
QLocale::AntiguaAndBarbuda 10
QLocale::Argentina 11
QLocale::Armenia 12
QLocale::Aruba 13
QLocale::AscensionIsland 14
QLocale::Australia 15
QLocale::Austria 16
QLocale::Azerbaijan 17
QLocale::Bahamas 18
QLocale::Bahrain 19
QLocale::Bangladesh 20
QLocale::Barbados 21
QLocale::Belarus 22
QLocale::Belgium 23
QLocale::Belize 24
QLocale::Benin 25
QLocale::Bermuda 26
QLocale::Bhutan 27
QLocale::Bolivia 28
QLocale::Bonaire CaribbeanNetherlands
QLocale::BosniaAndHerzegowina BosniaAndHerzegovina 过时,使用 BosniaAndHerzegovina 代替
QLocale::BosniaAndHerzegovina 29 Since 6.0
QLocale::Botswana 30
QLocale::BouvetIsland 31
QLocale::Brazil 32
QLocale::BritishIndianOceanTerritory 33
QLocale::BritishVirginIslands 34
QLocale::Brunei 35
QLocale::Bulgaria 36
QLocale::BurkinaFaso 37
QLocale::Burundi 38
QLocale::Cambodia 39
QLocale::Cameroon 40
QLocale::Canada 41
QLocale::CanaryIslands 42
QLocale::CaribbeanNetherlands 44
QLocale::CapeVerde 43
QLocale::CaymanIslands 45
QLocale::CentralAfricanRepublic 46
QLocale::CeutaAndMelilla 47
QLocale::Chad 48
QLocale::Chile 49
QLocale::China 50
QLocale::ChristmasIsland 51
QLocale::ClippertonIsland 52
QLocale::CocosIslands 53
QLocale::Colombia 54
QLocale::Comoros 55
QLocale::CongoBrazzaville 56
QLocale::CongoKinshasa 57
QLocale::CookIslands 58
QLocale::CostaRica 59
QLocale::Croatia 60
QLocale::Cuba 61
QLocale::Curacao 62 Since Qt 6.0
QLocale::CuraSao Curacao 过时,使用 Curacao 代替
QLocale::Cyprus 63
QLocale::Czechia 64 Since 6.0
QLocale::CzechRepublic Czechia 过时,使用 Czechia 代替
QLocale::DemocraticRepublicOfCongo CongoKinshasa 过时,使用 CongoKinshasa 代替
QLocale::DemocraticRepublicOfKorea NorthKorea 过时,使用 NorthKorea 代替
QLocale::Denmark 65
QLocale::DiegoGarcia 66
QLocale::Djibouti 67
QLocale::Dominica 68
QLocale::DominicanRepublic 69
QLocale::EastTimor TimorLeste
QLocale::Ecuador 70
QLocale::Egypt 71
QLocale::ElSalvador 72
QLocale::EquatorialGuinea 73
QLocale::Eritrea 74
QLocale::Estonia 75
QLocale::Eswatini 76
QLocale::Ethiopia 77
QLocale::EuropeanUnion 79 Since Qt 5.7
QLocale::Europe 78 Since Qt 5.12
QLocale::FalklandIslands 80
QLocale::FaroeIslands 81
QLocale::Fiji 82
QLocale::Finland 83
QLocale::France 84
QLocale::FrenchGuiana 85
QLocale::FrenchPolynesia 86
QLocale::FrenchSouthernTerritories 87
QLocale::Gabon 88
QLocale::Gambia 89
QLocale::Georgia 90
QLocale::Germany 91
QLocale::Ghana 92
QLocale::Gibraltar 93
QLocale::Greece 94
QLocale::Greenland 95
QLocale::Grenada 96
QLocale::Guadeloupe 97
QLocale::Guam 98
QLocale::Guatemala 99
QLocale::Guernsey 100
QLocale::Guinea 102
QLocale::GuineaBissau 101
QLocale::Guyana 103
QLocale::Haiti 104
QLocale::HeardAndMcDonaldIslands 105
QLocale::Honduras 106
QLocale::HongKong 107
QLocale::Hungary 108
QLocale::Iceland 109
QLocale::India 110
QLocale::Indonesia 111
QLocale::Iran 112
QLocale::Iraq 113
QLocale::Ireland 114
QLocale::IsleOfMan 115
QLocale::Israel 116
QLocale::Italy 117
QLocale::IvoryCoast 118
QLocale::Jamaica 119
QLocale::Japan 120
QLocale::Jersey 121
QLocale::Jordan 122
QLocale::Kazakhstan 123
QLocale::Kenya 124
QLocale::Kiribati 125
QLocale::Kosovo 126 Since Qt 5.2
QLocale::Kuwait 127
QLocale::Kyrgyzstan 128
QLocale::Laos 129
QLocale::LatinAmerica 130
QLocale::LatinAmericaAndTheCaribbean LatinAmerica 过时,使用 LatinAmerica 代替
QLocale::Latvia 131
QLocale::Lebanon 132
QLocale::Lesotho 133
QLocale::Liberia 134
QLocale::Libya 135
QLocale::Liechtenstein 136
QLocale::Lithuania 137
QLocale::Luxembourg 138
QLocale::Macao 139
QLocale::Macau Macao
QLocale::Macedonia 140
QLocale::Madagascar 141
QLocale::Malawi 142
QLocale::Malaysia 143
QLocale::Maldives 144
QLocale::Mali 145
QLocale::Malta 146
QLocale::MarshallIslands 147
QLocale::Martinique 148
QLocale::Mauritania 149
QLocale::Mauritius 150
QLocale::Mayotte 151
QLocale::Mexico 152
QLocale::Micronesia 153
QLocale::Moldova 154
QLocale::Monaco 155
QLocale::Mongolia 156
QLocale::Montenegro 157
QLocale::Montserrat 158
QLocale::Morocco 159
QLocale::Mozambique 160
QLocale::Myanmar 161
QLocale::Namibia 162
QLocale::NauruCountry NauruTerritory 过时别名对于 NauruTerritory
QLocale::NauruTerritory 163 Since 6.2
QLocale::Nepal 164
QLocale::Netherlands 165
QLocale::NewCaledonia 166
QLocale::NewZealand 167
QLocale::Nicaragua 168
QLocale::Niger 170
QLocale::Nigeria 169
QLocale::Niue 171
QLocale::NorfolkIsland 172
QLocale::NorthernMarianaIslands 173
QLocale::NorthKorea 174
QLocale::Norway 175
QLocale::Oman 176
QLocale::OutlyingOceania 177 Since Qt 5.7
QLocale::Pakistan 178
QLocale::Palau 179
QLocale::PalestinianTerritories 180
QLocale::Panama 181
QLocale::PapuaNewGuinea 182
QLocale::Paraguay 183
QLocale::PeoplesRepublicOfCongo CongoBrazzaville 过时,使用 CongoBrazzaville 代替
QLocale::Peru 184
QLocale::Philippines 185
QLocale::Pitcairn 186
QLocale::Poland 187
QLocale::Portugal 188
QLocale::PuertoRico 189
QLocale::Qatar 190
QLocale::RepublicOfKorea SouthKorea 过时,使用 SouthKorea 代替
QLocale::Reunion 191
QLocale::Romania 192
QLocale::RussianFederation Russia
QLocale::Russia 193
QLocale::Rwanda 194
QLocale::SaintBarthelemy 195
QLocale::SaintHelena 196
QLocale::SaintKittsAndNevis 197
QLocale::SaintLucia 198
QLocale::SaintMartin 199
QLocale::SaintPierreAndMiquelon 200
QLocale::SaintVincentAndGrenadines 201
QLocale::SaintVincentAndTheGrenadines SaintVincentAndGrenadines
QLocale::Samoa 202
QLocale::SanMarino 203
QLocale::SaoTomeAndPrincipe 204
QLocale::SaudiArabia 205
QLocale::Senegal 206
QLocale::Serbia 207
QLocale::Seychelles 208
QLocale::SierraLeone 209
QLocale::Singapore 210
QLocale::SintMaarten 211
QLocale::Slovakia 212
QLocale::Slovenia 213
QLocale::SolomonIslands 214
QLocale::Somalia 215
QLocale::SouthAfrica 216
QLocale::SouthGeorgiaAndSouthSandwichIslands 217
QLocale::SouthGeorgiaAndTheSouthSandwichIslands SouthGeorgiaAndSouthSandwichIslands
QLocale::SouthKorea 218
QLocale::SouthSudan 219
QLocale::Spain 220
QLocale::SriLanka 221
QLocale::Sudan 222
QLocale::Suriname 223
QLocale::SvalbardAndJanMayen 224
QLocale::SvalbardAndJanMayenIslands SvalbardAndJanMayen
QLocale::Swaziland Eswatini
QLocale::Sweden 225
QLocale::Switzerland 226
QLocale::Syria 227
QLocale::SyrianArabRepublic Syria 过时,使用 Syria 代替
QLocale::Taiwan 228
QLocale::Tajikistan 229
QLocale::Tanzania 230
QLocale::Thailand 231
QLocale::TimorLeste 232
QLocale::Togo 233
QLocale::TokelauCountry TokelauTerritory 过时别名对于 TokelauTerritory
QLocale::TokelauTerritory 234 Since 6.2
QLocale::Tonga 235
QLocale::TrinidadAndTobago 236
QLocale::TristanDaCunha 237
QLocale::Tunisia 238
QLocale::Turkey 239
QLocale::Turkmenistan 240
QLocale::TurksAndCaicosIslands 241
QLocale::TuvaluCountry TuvaluTerritory 过时别名对于 TuvaluTerritory
QLocale::TuvaluTerritory 242 Since 6.2
QLocale::Uganda 243
QLocale::Ukraine 244
QLocale::UnitedArabEmirates 245
QLocale::UnitedKingdom 246
QLocale::UnitedStates 248
QLocale::UnitedStatesOutlyingIslands 247
QLocale::UnitedStatesMinorOutlyingIslands UnitedStatesOutlyingIslands
QLocale::UnitedStatesVirginIslands 249
QLocale::Uruguay 250
QLocale::Uzbekistan 251
QLocale::Vanuatu 252
QLocale::VaticanCity 253
QLocale::VaticanCityState VaticanCity
QLocale::Venezuela 254
QLocale::Vietnam 255
QLocale::WallisAndFutuna 256
QLocale::WallisAndFutunaIslands WallisAndFutuna
QLocale::WesternSahara 257
QLocale::World 258 Since Qt 5.12
QLocale::Yemen 259
QLocale::Zambia 260
QLocale::Zimbabwe 261

注意: 使用针对此枚举的 Territory 别名,若可能。Country 枚举在以后的发行中应该被重命名成 Territory。

另请参阅 territory (), territoryToString (), codeToTerritory (),和 territoryToCode ().

enum QLocale:: CurrencySymbolFormat

指定货币符号的格式。

常量 描述
QLocale::CurrencyIsoCode 0 a ISO-4217 code of the currency.
QLocale::CurrencySymbol 1 a currency symbol.
QLocale::CurrencyDisplayName 2 a user readable name of the currency.

[since 5.10] enum QLocale:: DataSizeFormat
flags QLocale:: DataSizeFormats

Specifies the format for representation of data quantities.

常量 描述
QLocale::DataSizeIecFormat 0 format using base 1024 and IEC prefixes: KiB, MiB, GiB, ...
QLocale::DataSizeTraditionalFormat DataSizeSIQuantifiers format using base 1024 and SI prefixes: kB, MB, GB, ...
QLocale::DataSizeSIFormat DataSizeBase1000 | DataSizeSIQuantifiers format using base 1000 and SI prefixes: kB, MB, GB, ...

该枚举在 Qt 5.10 引入或被修改。

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

另请参阅 formattedDataSize ().

[since 5.7] enum QLocale:: FloatingPointPrecisionOption

This enum defines a constant that can be given as precision to QString::number (), QByteArray::number (),和 QLocale::toString () when converting floats or doubles, in order to express a variable number of digits as precision.

常量 描述
QLocale::FloatingPointShortest -128 The conversion algorithm will try to find the shortest accurate representation for the given number. "Accurate" means that you get the exact same number back from an inverse conversion on the generated string representation. In particular, trailing zeros are omitted (from the mantissa, in exponent formats).

该枚举在 Qt 5.7 引入或被修改。

另请参阅 toString (), QString::number (),和 QByteArray::number ().

enum QLocale:: FormatType

此枚举描述可以使用的不同格式,当转换 QDate , QTime ,和 QDateTime objects, as well as months and days, to strings specific to the locale.

常量 描述
QLocale::LongFormat 0 Longer format.
QLocale::ShortFormat 1 Shorter format.
QLocale::NarrowFormat 2 A special version for use when space is very limited.

注意: NarrowFormat might contain the same text for different months and days. 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 .

另请参阅 dateFormat (), timeFormat (), dateTimeFormat (), monthName (), standaloneMonthName (), dayName (), standaloneDayName (), toDate (), toTime (),和 toDateTime ().

enum QLocale:: Language

此枚举类型用于指定语言。

常量 描述
QLocale::AnyLanguage 0
QLocale::C 1 简化的 English 区域设置;见 QLocale::c ()
QLocale::Abkhazian 2
QLocale::Afan Oromo 过时,请使用 Oromo
QLocale::Afar 3
QLocale::Afrikaans 4
QLocale::Aghem 5
QLocale::Akan 6
QLocale::Akkadian 7 Since Qt 5.1
QLocale::Akoose 8 Since Qt 5.3
QLocale::Albanian 9
QLocale::AmericanSignLanguage 10 Since Qt 5.7
QLocale::Amharic 11
QLocale::AncientEgyptian 12 Since Qt 5.1
QLocale::AncientGreek 13 Since Qt 5.1
QLocale::Arabic 14
QLocale::Aragonese 15 Since Qt 5.1
QLocale::Aramaic 16 Since Qt 5.1
QLocale::Armenian 17
QLocale::Assamese 18
QLocale::Asturian 19
QLocale::Asu 20
QLocale::Atsam 21
QLocale::Avaric 22
QLocale::Avestan 23
QLocale::Aymara 24
QLocale::Azerbaijani 25
QLocale::Bafia 26
QLocale::Balinese 27 Since Qt 5.1
QLocale::Bambara 28
QLocale::Bamun 29 Since Qt 5.1
QLocale::Bangla 30 Since Qt 6.0
QLocale::Basaa 31
QLocale::Bashkir 32
QLocale::Basque 33
QLocale::BatakToba 34 Since Qt 5.1
QLocale::Belarusian 35
QLocale::Bemba 36
QLocale::Bena 37
QLocale::Bengali Bangla 过时,请使用 Bangla
QLocale::Bhojpuri 38 Since Qt 5.7
QLocale::Bhutani Dzongkha 过时,请使用 Dzongkha
QLocale::Bislama 39
QLocale::Blin 40
QLocale::Bodo 41
QLocale::Bosnian 42
QLocale::Breton 43
QLocale::Buginese 44 Since Qt 5.1
QLocale::Bulgarian 45
QLocale::Burmese 46
QLocale::Byelorussian Belarusian 过时,请使用 Belarusian
QLocale::Cambodian Khmer 过时,请使用 Khmer
QLocale::Cantonese 47 Since Qt 5.7
QLocale::Catalan 48
QLocale::Cebuano 49 Since Qt 5.14
QLocale::CentralAtlasTamazight 50 Since Qt 6.0
QLocale::CentralKurdish 51 Since Qt 5.5
QLocale::CentralMoroccoTamazight CentralAtlasTamazight 过时,请使用 CentralAtlasTamazight
QLocale::Chakma 52 Since Qt 5.1
QLocale::Chamorro 53
QLocale::Chechen 54
QLocale::Cherokee 55
QLocale::Chewa Nyanja 过时,请使用 Nyanja
QLocale::Chickasaw 56 Since Qt 5.14
QLocale::Chiga 57
QLocale::Chinese 58 (普通话)
QLocale::Church 59
QLocale::Chuvash 60
QLocale::Colognian 61
QLocale::Coptic 62 Since Qt 5.1
QLocale::Cornish 63
QLocale::Corsican 64
QLocale::Cree 65
QLocale::Croatian 66
QLocale::Czech 67
QLocale::Danish 68
QLocale::Divehi 69
QLocale::Dogri 70 Since Qt 5.1
QLocale::Duala 71
QLocale::Dutch 72
QLocale::Dzongkha 73
QLocale::Embu 74
QLocale::English 75
QLocale::Erzya 76 Since Qt 5.14
QLocale::Esperanto 77
QLocale::Estonian 78
QLocale::Ewe 79
QLocale::Ewondo 80
QLocale::Faroese 81
QLocale::Fijian 82
QLocale::Filipino 83
QLocale::Finnish 84
QLocale::French 85
QLocale::Frisian WesternFrisian 如同 WesternFrisian
QLocale::Friulian 86
QLocale::Fulah 87
QLocale::Ga 89
QLocale::Gaelic 88
QLocale::Galician 90
QLocale::Ganda 91
QLocale::Geez 92
QLocale::Georgian 93
QLocale::German 94
QLocale::Gothic 95 Since Qt 5.1
QLocale::Greek 96
QLocale::Greenlandic Kalaallisut 过时,请使用 Kalaallisut
QLocale::Guarani 97
QLocale::Gujarati 98
QLocale::Gusii 99
QLocale::Haitian 100
QLocale::Hausa 101
QLocale::Hawaiian 102
QLocale::Hebrew 103
QLocale::Herero 104
QLocale::Hindi 105
QLocale::HiriMotu 106
QLocale::Hungarian 107
QLocale::Icelandic 108
QLocale::Ido 109 Since Qt 5.12
QLocale::Igbo 110
QLocale::InariSami 111 Since Qt 5.5
QLocale::Indonesian 112
QLocale::Ingush 113 Since Qt 5.1
QLocale::Interlingua 114
QLocale::Interlingue 115
QLocale::Inuktitut 116
QLocale::Inupiak Inupiaq 过时,请使用 Inupiaq
QLocale::Inupiaq 117 Since 6.0
QLocale::Irish 118
QLocale::Italian 119
QLocale::Japanese 120
QLocale::Javanese 121
QLocale::Jju 122
QLocale::JolaFonyi 123
QLocale::Kabuverdianu 124
QLocale::Kabyle 125
QLocale::Kako 126
QLocale::Kalaallisut 127 Since Qt 6.0
QLocale::Kalenjin 128
QLocale::Kamba 129
QLocale::Kannada 130
QLocale::Kanuri 131
QLocale::Kashmiri 132
QLocale::Kazakh 133
QLocale::Kenyang 134 Since Qt 5.5
QLocale::Khmer 135
QLocale::Kiche 136 Since Qt 5.5
QLocale::Kikuyu 137
QLocale::Kinyarwanda 138
QLocale::Kirghiz Kyrgyz 过时,请使用 Kyrgyz
QLocale::Komi 139
QLocale::Kongo 140
QLocale::Konkani 141
QLocale::Korean 142
QLocale::Koro 143
QLocale::KoyraboroSenni 144
QLocale::KoyraChiini 145
QLocale::Kpelle 146
QLocale::Kuanyama 147 Since 6.0
QLocale::Kurdish 148
QLocale::Kurundi Rundi 过时,请使用 Rundi
QLocale::Kwanyama Kuanyama 过时,请使用 Kuanyama
QLocale::Kwasio 149
QLocale::Kyrgyz 150 Since 6.0
QLocale::Lakota 151 Since Qt 5.3
QLocale::Langi 152
QLocale::Lao 153
QLocale::Latin 154
QLocale::Latvian 155
QLocale::Lezghian 156 Since Qt 5.5
QLocale::Limburgish 157
QLocale::Lingala 158
QLocale::LiteraryChinese 159 Since Qt 5.7
QLocale::Lithuanian 160
QLocale::Lojban 161 Since Qt 5.12
QLocale::LowerSorbian 162 Since Qt 5.5
QLocale::LowGerman 163
QLocale::LubaKatanga 164
QLocale::LuleSami 165 Since Qt 5.5
QLocale::Luo 166
QLocale::Luxembourgish 167
QLocale::Luyia 168
QLocale::Macedonian 169
QLocale::Machame 170
QLocale::Maithili 171 Since Qt 5.5
QLocale::MakhuwaMeetto 172
QLocale::Makonde 173
QLocale::Malagasy 174
QLocale::Malay 176
QLocale::Malayalam 175
QLocale::Maltese 177
QLocale::Mandingo 178 Since Qt 5.1
QLocale::Manipuri 179 Since Qt 5.1
QLocale::Manx 180
QLocale::Maori 181
QLocale::Mapuche 182 Since Qt 5.5
QLocale::Marathi 183
QLocale::Marshallese 184
QLocale::Masai 185
QLocale::Mazanderani 186 Since Qt 5.7
QLocale::Mende 187 Since Qt 5.5
QLocale::Meru 188
QLocale::Meta 189
QLocale::Mohawk 190 Since Qt 5.5
QLocale::Mongolian 191
QLocale::Morisyen 192
QLocale::Mundang 193
QLocale::Muscogee 194 Since Qt 5.14
QLocale::Nama 195
QLocale::NauruLanguage 196
QLocale::Navaho Navajo 过时,请使用 Navajo
QLocale::Navajo 197 Since 6.0
QLocale::Ndonga 198
QLocale::Nepali 199
QLocale::Newari 200 Since Qt 5.7
QLocale::Ngiemboon 201
QLocale::NigerianPidgin 203 Since Qt 6.0
QLocale::Ngomba 202
QLocale::Nko 204 Since Qt 5.5
QLocale::NorthernLuri 205 Since Qt 5.7
QLocale::NorthernSami 206
QLocale::NorthernSotho 207
QLocale::NorthNdebele 208
QLocale::NorwegianBokmal 209
QLocale::NorwegianNynorsk 210
QLocale::Nuer 211
QLocale::Nyanja 212
QLocale::Nyankole 213
QLocale::Occitan 214
QLocale::Odia 215 Since 6.0
QLocale::Ojibwa 216
QLocale::OldIrish 217 Since Qt 5.1
QLocale::OldNorse 218 Since Qt 5.1
QLocale::OldPersian 219 Since Qt 5.1
QLocale::Oriya Odia 过时,请使用 Odia
QLocale::Oromo 220
QLocale::Osage 221 Since Qt 5.7
QLocale::Ossetic 222
QLocale::Pahlavi 223 Since Qt 5.1
QLocale::Palauan 224 Since Qt 5.7
QLocale::Pali 225
QLocale::Papiamento 226 Since Qt 5.7
QLocale::Pashto 227
QLocale::Persian 228
QLocale::Phoenician 229 Since Qt 5.1
QLocale::Polish 230
QLocale::Portuguese 231
QLocale::Prussian 232 Since Qt 5.5
QLocale::Punjabi 233
QLocale::Quechua 234
QLocale::RhaetoRomance Romansh 过时,请使用 Romansh
QLocale::Romanian 235
QLocale::Romansh 236
QLocale::Rombo 237
QLocale::Rundi 238
QLocale::Russian 239
QLocale::Rwa 240
QLocale::Saho 241
QLocale::Sakha 242
QLocale::Samburu 243
QLocale::Samoan 244
QLocale::Sango 245
QLocale::Sangu 246
QLocale::Sanskrit 247
QLocale::Santali 248 Since Qt 5.1
QLocale::Sardinian 249
QLocale::Saurashtra 250 Since Qt 5.1
QLocale::Sena 251
QLocale::Serbian 252
QLocale::Shambala 253
QLocale::Shona 254
QLocale::SichuanYi 255
QLocale::Sicilian 256 Since Qt 5.12
QLocale::Sidamo 257
QLocale::Silesian 258 Since Qt 5.14
QLocale::Sindhi 259
QLocale::Sinhala 260
QLocale::SkoltSami 261 Since Qt 5.5
QLocale::Slovak 262
QLocale::Slovenian 263
QLocale::Soga 264
QLocale::Somali 265
QLocale::SouthernKurdish 266 Since Qt 5.12
QLocale::SouthernSami 267 Since Qt 5.5
QLocale::SouthernSotho 268
QLocale::SouthNdebele 269
QLocale::Spanish 270
QLocale::StandardMoroccanTamazight 271 Since Qt 5.3
QLocale::Sundanese 272
QLocale::Swahili 273
QLocale::Swati 274
QLocale::Swedish 275
QLocale::SwissGerman 276
QLocale::Syriac 277
QLocale::Tachelhit 278
QLocale::Tahitian 279
QLocale::TaiDam 280 Since Qt 5.1
QLocale::Taita 281
QLocale::Tajik 282
QLocale::Tamil 283
QLocale::Taroko 284
QLocale::Tasawaq 285
QLocale::Tatar 286
QLocale::Telugu 287
QLocale::Teso 288
QLocale::Thai 289
QLocale::Tibetan 290
QLocale::Tigre 291
QLocale::Tigrinya 292
QLocale::TokelauLanguage 293 Since Qt 5.7
QLocale::TokPisin 294 Since Qt 5.7
QLocale::Tongan 295
QLocale::Tsonga 296
QLocale::Tswana 297
QLocale::Turkish 298
QLocale::Turkmen 299
QLocale::TuvaluLanguage 300 Since Qt 5.7
QLocale::Tyap 301
QLocale::Ugaritic 302 Since Qt 5.1
QLocale::Uighur Uyghur 过时,请使用 Uyghur
QLocale::Uigur Uyghur 过时,请使用 Uyghur
QLocale::Ukrainian 303
QLocale::UpperSorbian 304 Since Qt 5.5
QLocale::Urdu 305
QLocale::Uyghur 306 Since 6.0
QLocale::Uzbek 307
QLocale::Vai 308
QLocale::Venda 309
QLocale::Vietnamese 310
QLocale::Volapuk 311
QLocale::Vunjo 312
QLocale::Walamo Wolaytta 过时,请使用 Wolaytta
QLocale::Walloon 313
QLocale::Walser 314
QLocale::Warlpiri 315 Since Qt 5.5
QLocale::Welsh 316
QLocale::WesternBalochi 317 Since Qt 5.12
QLocale::WesternFrisian 318 如同 Frisian
QLocale::Wolaytta 319 Since 6.0
QLocale::Wolof 320
QLocale::Xhosa 321
QLocale::Yangben 322
QLocale::Yiddish 323
QLocale::Yoruba 324
QLocale::Zarma 325
QLocale::Zhuang 326
QLocale::Zulu 327

另请参阅 language () 和 languageToString ().

enum QLocale:: MeasurementSystem

此枚举定义用于度量的单位。

常量 描述
QLocale::MetricSystem 0 This value indicates metric units, such as meters, centimeters and millimeters.
QLocale::ImperialUSSystem 1 This value indicates imperial units, such as inches and miles as they are used in the United States.
QLocale::ImperialUKSystem 2 This value indicates imperial units, such as inches and miles as they are used in the United Kingdom.
QLocale::ImperialSystem ImperialUSSystem Provided for compatibility. Same as ImperialUSSystem

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 () 和设置采用 setNumberOptions ().

常量 描述
QLocale::DefaultNumberOptions 0x0 This option represents the default behavior, with group separators, with one leading zero in single digit exponents, and without trailing zeroes after the decimal dot.
QLocale::OmitGroupSeparator 0x01 If 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::RejectGroupSeparator 0x02 If 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.
QLocale::OmitLeadingZeroInExponent 0x04 If this option is set, the number-to-string functions will not pad exponents with zeroes when printing floating point numbers in scientific notation. The default is to add one leading zero to single digit exponents.
QLocale::RejectLeadingZeroInExponent 0x08 If this option is set, the string-to-number functions will fail if they encounter an exponent padded with zeroes when parsing a floating point number in scientific notation. The default is to accept such padding.
QLocale::IncludeTrailingZeroesAfterDot 0x10 If this option is set, the number-to-string functions will pad numbers with zeroes to the requested precision in "g" or "most concise" mode, even if the number of significant digits is lower than the requested precision. The default is to omit trailing zeroes.
QLocale::RejectTrailingZeroesAfterDot 0x20 If this option is set, the string-to-number functions will fail if they encounter trailing zeroes after the decimal dot when parsing a number in scientific or decimal representation. The default is to accept trailing zeroes.

NumberOptions 类型是 typedef 对于 QFlags <NumberOption>. It stores an OR combination of NumberOption values.

另请参阅 setNumberOptions (), numberOptions (),和 FloatingPointPrecisionOption .

enum QLocale:: QuotationStyle

此枚举为区域设置特定引号,定义一组可能的样式。

常量 描述
QLocale::StandardQuotation 0 If this option is set, the standard quotation marks will be used to quote strings.
QLocale::AlternateQuotation 1 If this option is set, the alternate quotation marks will be used to quote strings.

另请参阅 quoteString ().

enum QLocale:: Script

此枚举类型用于指定脚本。

常量 描述
QLocale::AnyScript 0
QLocale::AdlamScript 1 Since Qt 5.7
QLocale::AhomScript 2 Since Qt 5.7
QLocale::AnatolianHieroglyphsScript 3 Since Qt 5.7
QLocale::ArabicScript 4
QLocale::ArmenianScript 5
QLocale::AvestanScript 6 Since Qt 5.1
QLocale::BalineseScript 7 Since Qt 5.1
QLocale::BamumScript 8 Since Qt 5.1
QLocale::BanglaScript 9 Since 6.0
QLocale::BassaVahScript 10 Since Qt 5.5
QLocale::BatakScript 11 Since Qt 5.1
QLocale::BengaliScript BanglaScript 过时,请使用 BanglaScript
QLocale::BhaiksukiScript 12 Since Qt 5.7
QLocale::BopomofoScript 13 Since Qt 5.1
QLocale::BrahmiScript 14 Since Qt 5.1
QLocale::BrailleScript 15 Since Qt 5.1
QLocale::BugineseScript 16 Since Qt 5.1
QLocale::BuhidScript 17 Since Qt 5.1
QLocale::CanadianAboriginalScript 18 Since Qt 5.1
QLocale::CarianScript 19 Since Qt 5.1
QLocale::CaucasianAlbanianScript 20 Since Qt 5.5
QLocale::ChakmaScript 21 Since Qt 5.1
QLocale::ChamScript 22 Since Qt 5.1
QLocale::CherokeeScript 23
QLocale::CopticScript 24 Since Qt 5.1
QLocale::CuneiformScript 25 Since Qt 5.1
QLocale::CypriotScript 26 Since Qt 5.1
QLocale::CyrillicScript 27
QLocale::DeseretScript 28 Since Qt 5.1
QLocale::DevanagariScript 29
QLocale::DuployanScript 30 Since Qt 5.5
QLocale::EgyptianHieroglyphsScript 31 Since Qt 5.1
QLocale::ElbasanScript 32 Since Qt 5.5
QLocale::EthiopicScript 33
QLocale::FraserScript 34 Since Qt 5.1
QLocale::GeorgianScript 35
QLocale::GlagoliticScript 36 Since Qt 5.1
QLocale::GothicScript 37 Since Qt 5.1
QLocale::GranthaScript 38 Since Qt 5.5
QLocale::GreekScript 39
QLocale::GujaratiScript 40
QLocale::GurmukhiScript 41
QLocale::HangulScript 42 Since Qt 5.1
QLocale::HanScript 43 Since Qt 5.1
QLocale::HanunooScript 44 Since Qt 5.1
QLocale::HanWithBopomofoScript 45 Since Qt 5.7
QLocale::HatranScript 46 Since Qt 5.7
QLocale::HebrewScript 47
QLocale::HiraganaScript 48 Since Qt 5.1
QLocale::ImperialAramaicScript 49 Since Qt 5.1
QLocale::InscriptionalPahlaviScript 50 Since Qt 5.1
QLocale::InscriptionalParthianScript 51 Since Qt 5.1
QLocale::JamoScript 52 Since Qt 5.7
QLocale::JapaneseScript 53
QLocale::JavaneseScript 54 Since Qt 5.1
QLocale::KaithiScript 55 Since Qt 5.1
QLocale::KannadaScript 56
QLocale::KatakanaScript 57 Since Qt 5.1
QLocale::KayahLiScript 58 Since Qt 5.1
QLocale::KharoshthiScript 59 Since Qt 5.1
QLocale::KhmerScript 60 Since Qt 5.1
QLocale::KhojkiScript 61 Since Qt 5.5
QLocale::KhudawadiScript 62 Since Qt 5.5
QLocale::KoreanScript 63
QLocale::LannaScript 64 Since Qt 5.1
QLocale::LaoScript 65
QLocale::LatinScript 66
QLocale::LepchaScript 67 Since Qt 5.1
QLocale::LimbuScript 68 Since Qt 5.1
QLocale::LinearAScript 69 Since Qt 5.5
QLocale::LinearBScript 70 Since Qt 5.1
QLocale::LycianScript 71 Since Qt 5.1
QLocale::LydianScript 72 Since Qt 5.1
QLocale::MahajaniScript 73 Since Qt 5.5
QLocale::MalayalamScript 74
QLocale::MandaeanScript 75 Since Qt 5.1
QLocale::ManichaeanScript 76 Since Qt 5.5
QLocale::MarchenScript 77 Since Qt 5.7
QLocale::MeiteiMayekScript 78 Since Qt 5.1
QLocale::MendeScript 79 Since Qt 6.0
QLocale::MendeKikakuiScript MendeScript 过时,请使用 MendeScript
QLocale::MeroiticCursiveScript 80 Since Qt 5.1
QLocale::MeroiticScript 81 Since Qt 5.1
QLocale::ModiScript 82 Since Qt 5.5
QLocale::MongolianScript 83
QLocale::MroScript 84 Since Qt 5.5
QLocale::MultaniScript 85 Since Qt 5.7
QLocale::MyanmarScript 86
QLocale::NabataeanScript 87 Since Qt 5.5
QLocale::NewaScript 88 Since Qt 5.7
QLocale::NewTaiLueScript 89 Since Qt 5.1
QLocale::NkoScript 90 Since Qt 5.1
QLocale::OghamScript 92 Since Qt 5.1
QLocale::OlChikiScript 93 Since Qt 5.1
QLocale::OldHungarianScript 94 Since Qt 5.7
QLocale::OldItalicScript 95 Since Qt 5.1
QLocale::OldNorthArabianScript 96 Since Qt 5.5
QLocale::OldPermicScript 97 Since Qt 5.5
QLocale::OldPersianScript 98 Since Qt 5.1
QLocale::OldSouthArabianScript 99 Since Qt 5.1
QLocale::OdiaScript 91 Since 6.0
QLocale::OriyaScript OdiaScript 过时,请使用 OdiaScript
QLocale::OrkhonScript 100 Since Qt 5.1
QLocale::OsageScript 101 Since Qt 5.7
QLocale::OsmanyaScript 102 Since Qt 5.1
QLocale::PahawhHmongScript 103 Since Qt 5.5
QLocale::PalmyreneScript 104 Since Qt 5.5
QLocale::PauCinHauScript 105 Since Qt 5.5
QLocale::PhagsPaScript 106 Since Qt 5.1
QLocale::PhoenicianScript 107 Since Qt 5.1
QLocale::PollardPhoneticScript 108 Since Qt 5.1
QLocale::PsalterPahlaviScript 109 Since Qt 5.5
QLocale::RejangScript 110 Since Qt 5.1
QLocale::RunicScript 111 Since Qt 5.1
QLocale::SamaritanScript 112 Since Qt 5.1
QLocale::SaurashtraScript 113 Since Qt 5.1
QLocale::SharadaScript 114 Since Qt 5.1
QLocale::ShavianScript 115 Since Qt 5.1
QLocale::SiddhamScript 116 Since Qt 5.5
QLocale::SignWritingScript 117 Since Qt 5.7
QLocale::SimplifiedChineseScript SimplifiedHanScript 如同 SimplifiedHanScript
QLocale::SimplifiedHanScript 118 如同 SimplifiedChineseScript
QLocale::SinhalaScript 119
QLocale::SoraSompengScript 120 Since Qt 5.1
QLocale::SundaneseScript 121 Since Qt 5.1
QLocale::SylotiNagriScript 122 Since Qt 5.1
QLocale::SyriacScript 123
QLocale::TagalogScript 124 Since Qt 5.1
QLocale::TagbanwaScript 125 Since Qt 5.1
QLocale::TaiLeScript 126 Since Qt 5.1
QLocale::TaiVietScript 127 Since Qt 5.1
QLocale::TakriScript 128 Since Qt 5.1
QLocale::TamilScript 129
QLocale::TangutScript 130 Since Qt 5.7
QLocale::TeluguScript 131
QLocale::ThaanaScript 132
QLocale::ThaiScript 133
QLocale::TibetanScript 134
QLocale::TifinaghScript 135
QLocale::TirhutaScript 136 Since Qt 5.5
QLocale::TraditionalChineseScript TraditionalHanScript 如同 TraditionalHanScript
QLocale::TraditionalHanScript 137 如同 TraditionalChineseScript
QLocale::UgariticScript 138 Since Qt 5.1
QLocale::VaiScript 139
QLocale::VarangKshitiScript 140 Since Qt 5.5
QLocale::YiScript 141

另请参阅 script (), scriptToString (),和 languageToString ().

[alias] QLocale:: Territory

此枚举类型是别名化的 Country , which shall be renamed to Territory at a future release.

另请参阅 territory () 和 territoryToString ().

成员函数文档编制

QLocale:: QLocale (const QLocale & other )

构造 QLocale 对象作为副本为 other .

QLocale:: QLocale ( QLocale::Language language , QLocale::Script script = AnyScript, QLocale::Territory territory = AnyTerritory)

构造 QLocale 对象为指定 language , script and territory .

若 QLocale 没有针对给定组合的数据,就会查找尽可能好的匹配数据 (若它可以)。它会回退到默认区域设置若

  • language is AnyLanguage 且无法推断语言从 script and territory
  • QLocale 没有语言数据,给定如 language 或如以上推断。

另请参阅 setDefault () 和 语言、脚本和地区的匹配组合 .

QLocale:: QLocale ( QLocale::Language language , QLocale::Territory territory )

构造 QLocale 对象为指定 language and territory .

If there is more than one script in use for this combination, a likely script will be selected. If QLocale has no data for the specified language , the default locale is used. If QLocale has no data for the specified combination of language and territory , an alternative territory may be used instead.

另请参阅 setDefault () 和 语言、脚本和地区的匹配组合 .

QLocale:: QLocale (const QString & name )

构造 QLocale 对象采用指定 name , which has the format "language[_script][_territory][.codeset][@modifier]" or "C", where:

  • language is a lowercase, two-letter, ISO 639 language code (some three-letter codes are also recognized),
  • script is a capitalized, four-letter, ISO 15924 script code,
  • territory is an uppercase, two-letter, ISO 3166 territory code (some numeric codes are also recognized), and
  • codeset and modifier are ignored.

The separator can be either underscore '_' (U+005F, "low line") or a dash '-' (U+002D, "hyphen-minus"). If QLocale has no data for the specified combination of language, script, and territory, then it uses the most suitable match it can find instead. If the string violates the locale format, or no suitable data can be found for the specified keys, the "C" locale is used instead.

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

另请参阅 bcp47Name () 和 语言、脚本和地区的匹配组合 .

QLocale:: QLocale ()

构造 QLocale 对象,初始化采用默认区域设置。

If no default locale was set using setDefault (), this locale will be the same as the one returned by system ().

另请参阅 setDefault ().

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

赋值 other 到此 QLocale 对象并返回引用为此 QLocale 对象。

QLocale:: ~QLocale ()

析构函数

QString QLocale:: amText () const

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

另请参阅 pmText ().

QString QLocale:: bcp47Name () const

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

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

此函数会试着使区域设置名称符合 BCP47。

另请参阅 language (), territory (), script (),和 uiLanguages ().

[static] QLocale QLocale:: c ()

返回 QLocale 对象被初始化成 C 区域设置。

This locale is based on en_US but with various quirks of its own, such as simplified number formatting and its own date formatting. It implements the POSIX standards that describe the behavior of standard library functions of the "C" programming language.

Among other things, this means its collation order is based on the ASCII values of letters, so that (for case-sensitive sorting) all upper-case letters sort before any lower-case one (rather than each letter's upper- and lower-case forms sorting adjacent to one another, before the next letter's two forms).

另请参阅 system ().

[static, since 6.1] QLocale::Language QLocale:: codeToLanguage ( QStringView languageCode )

返回 QLocale::Language enum corresponding to the two- or three-letter languageCode , as defined in the ISO 639 standards.

若代码无效或未知 QLocale::AnyLanguage 被返回。

该函数在 Qt 6.1 引入。

另请参阅 languageToCode (), codeToTerritory (),和 codeToScript ().

[static, since 6.1] QLocale::Script QLocale:: codeToScript ( QStringView scriptCode )

返回 QLocale::Script enum corresponding to the four-letter script scriptCode , 如 ISO 15924 标准定义的。

若代码无效或未知 QLocale::AnyScript 被返回。

该函数在 Qt 6.1 引入。

另请参阅 scriptToCode (), codeToLanguage (),和 codeToTerritory ().

[static, since 6.2] QLocale::Territory QLocale:: codeToTerritory ( QStringView territoryCode )

Returns the QLocale::Territory enum corresponding to the two-letter or three-digit territoryCode ,如 ISO 3166 标准定义的。

若代码无效或未知 QLocale::AnyTerritory 被返回。

该函数在 Qt 6.2 引入。

另请参阅 territoryToCode (), codeToLanguage (),和 codeToScript ().

[since 5.13] QLocale QLocale:: collation () const

返回用于整理的区域设置。

The result is usually this locale; however, the system locale (which is commonly the default locale) will return the system collation locale. The result is suitable for passing to QCollator 的构造函数。

该函数在 Qt 5.13 引入。

另请参阅 QCollator .

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.

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

返回货币符号根据 format .

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

Returns the date format used for the current locale.

format is LongFormat , the format will be elaborate, otherwise it will be short. For example, LongFormat en_US locale is dddd, MMMM d, yyyy , ShortFormat is M/d/yy .

另请参阅 QDate::toString () 和 QDate::fromString ().

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

Returns the date time format used for the current locale.

format is LongFormat , the format will be elaborate, otherwise it will be short. For example, LongFormat en_US locale is dddd, MMMM d, yyyy h:mm:ss AP t , ShortFormat is M/d/yy h:mm AP .

另请参阅 QDateTime::toString () 和 QDateTime::fromString ().

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

例如,若区域设置为 en_US and day is 1, LongFormat 将返回 Monday , ShortFormat Mon ,和 NarrowFormat M .

另请参阅 monthName () 和 standaloneDayName ().

QString QLocale:: decimalPoint () const

Returns the decimal point character of this locale.

另请参阅 groupSeparator () 和 toString ().

QString QLocale:: exponential () const

Returns the exponential character of this locale, used to separate exponent from mantissa in some floating-point numeric representations.

另请参阅 toString (double, char, int).

Qt::DayOfWeek QLocale:: firstDayOfWeek () const

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

[since 5.10] QString QLocale:: formattedDataSize ( qint64 bytes , int precision = 2, QLocale::DataSizeFormats format = DataSizeIecFormat) const

Converts a size in bytes to a human-readable localized string, comprising a number and a quantified unit. The quantifier is chosen such that the number is at least one, and as small as possible. For example if bytes is 16384, precision is 2, and format is DataSizeIecFormat (the default), this function returns "16.00 KiB"; for 1330409069609 bytes it returns "1.21 GiB"; and so on. If format is DataSizeIecFormat or DataSizeTraditionalFormat , the given number of bytes is divided by a power of 1024, with result less than 1024; for DataSizeSIFormat , it is divided by a power of 1000, with result less than 1000. DataSizeIecFormat uses the new IEC standard quantifiers Ki, Mi and so on, whereas DataSizeSIFormat uses the older SI quantifiers k, M, etc., and DataSizeTraditionalFormat abuses them.

该函数在 Qt 5.10 引入。

QString QLocale:: groupSeparator () const

返回此区域设置的组分隔符。

另请参阅 decimalPoint () 和 toString ().

QLocale::Language QLocale:: language () const

返回此区域设置的语言。

另请参阅 script (), territory (), languageToString (),和 bcp47Name ().

[static, since 6.1] QString QLocale:: languageToCode ( QLocale::Language language )

Returns the two- or three-letter language code for language , as defined in the ISO 639 standards.

注意: For QLocale::C 函数返回 "C" 。对于 QLocale::AnyLanguage 返回空字符串。

该函数在 Qt 6.1 引入。

另请参阅 codeToLanguage (), language (), name (), bcp47Name (), territoryToCode (),和 scriptToCode ().

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

返回 QString 包含名称对于 language .

另请参阅 territoryToString (), scriptToString (),和 bcp47Name ().

[static] QList < QLocale > QLocale:: matchingLocales ( QLocale::Language language , QLocale::Script script , QLocale::Territory territory )

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

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

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

QLocale::MeasurementSystem QLocale:: measurementSystem () const

返回区域设置的度量系统。

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

返回本地化名称为 month ,按格式指定通过 type .

例如,若区域设置为 en_US and month is 1, LongFormat 将返回 January . ShortFormat Jan ,和 NarrowFormat J .

另请参阅 dayName () 和 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.

另请参阅 QLocale (), language (), script (), territory (),和 bcp47Name ().

QString QLocale:: nativeLanguageName () const

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

另请参阅 nativeTerritoryName () 和 languageToString ().

[since 6.2] QString QLocale:: nativeTerritoryName () const

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

该函数在 Qt 6.2 引入。

另请参阅 nativeLanguageName () 和 territoryToString ().

QString QLocale:: negativeSign () const

Returns the negative sign character of this locale.

另请参阅 positiveSign () 和 toString ().

QLocale::NumberOptions QLocale:: numberOptions () const

Returns the options related to number conversions for this QLocale 实例。

By default, no options are set for the standard locales, except for the "C" locale, which has OmitGroupSeparator set by default.

另请参阅 setNumberOptions (), toString (), groupSeparator (),和 FloatingPointPrecisionOption .

QString QLocale:: percent () const

返回此区域设置的百分比字符。

另请参阅 toString ().

QString QLocale:: pmText () const

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

另请参阅 amText ().

QString QLocale:: positiveSign () const

返回此区域设置的正号字符。

另请参阅 negativeSign () 和 toString ().

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

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

[since 6.0] QString QLocale:: quoteString ( QStringView str , QLocale::QuotationStyle style = StandardQuotation) const

这是重载函数。

该函数在 Qt 6.0 引入。

QLocale::Script QLocale:: script () const

返回此区域设置的脚本。

另请参阅 language (), territory (), languageToString (), scriptToString (),和 bcp47Name ().

[static, since 6.1] QString QLocale:: scriptToCode ( QLocale::Script script )

返回 4 字母脚本代码为 script , 如 ISO 15924 标准定义的。

注意: For QLocale::AnyScript 返回空字符串。

该函数在 Qt 6.1 引入。

另请参阅 script (), name (), bcp47Name (), languageToCode (),和 territoryToCode ().

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

返回 QString 包含名称对于 script .

另请参阅 languageToString (), territoryToString (), script (),和 bcp47Name ().

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

将全局默认区域设置设为 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.

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

警告: 此函数不 可重入 .

另请参阅 system () 和 c ().

void QLocale:: setNumberOptions ( QLocale::NumberOptions options )

设置 options related to number conversions for this QLocale 实例。

另请参阅 numberOptions () 和 FloatingPointPrecisionOption .

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

另请参阅 dayName () 和 standaloneMonthName ().

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

返回本地化名称为 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 ().

另请参阅 monthName () 和 standaloneDayName ().

[since 5.6] void QLocale:: swap ( QLocale & other )

交换区域设置 other 与此区域设置。此操作非常快且从不失败。

该函数在 Qt 5.6 引入。

[static] QLocale QLocale:: system ()

返回 QLocale object initialized to the system locale.

The system locale may use system-specific sources for locale data, where available, otherwise falling back on QLocale 's built-in database entry for the language, script and territory the system reports.

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

另请参阅 c ().

[since 6.2] QLocale::Territory QLocale:: territory () const

返回此区域设置的地区。

该函数在 Qt 6.2 引入。

另请参阅 language (), script (), territoryToString (),和 bcp47Name ().

[static, since 6.2] QString QLocale:: territoryToCode ( QLocale::Territory territory )

返回 2 字母地区代码为 territory ,如 ISO 3166 标准定义的。

注意: For QLocale::AnyTerritory 返回空字符串。

该函数在 Qt 6.2 引入。

另请参阅 codeToTerritory (), territory (), name (), bcp47Name (), languageToCode (),和 scriptToCode ().

[static, since 6.2] QString QLocale:: territoryToString ( QLocale::Territory territory )

返回 QString 包含名称对于 territory .

该函数在 Qt 6.2 引入。

另请参阅 languageToString (), scriptToString (), territory (),和 bcp47Name ().

Qt::LayoutDirection QLocale:: textDirection () const

返回语言的文本方向。

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

返回用于当前区域设置的时间格式。

format is LongFormat , the format will be elaborate, otherwise it will be short. For example, LongFormat en_US locale is h:mm:ss AP t , ShortFormat is h:mm AP .

另请参阅 QTime::toString () 和 QTime::fromString ().

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

返回本地化字符串表示为 value 以货币方式。若 symbol is provided it is used instead of the default currency symbol.

另请参阅 currencySymbol ().

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

这是重载函数。

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

这是重载函数。

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

这是重载函数。

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

这是重载函数。

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

这是重载函数。

[since 5.7] QString QLocale:: toCurrencyString ( double value , const QString & symbol = QString(), int precision = -1) const

此函数重载 toCurrencyString()。

返回本地化字符串表示为 value 以货币方式。若 symbol is provided it is used instead of the default currency symbol. If the precision is provided it is used to set the precision of the currency value.

该函数在 Qt 5.7 引入。

另请参阅 currencySymbol ().

QString QLocale:: toCurrencyString ( float i , const QString & symbol = QString(), int precision = -1) const

此函数重载 toCurrencyString()。

QDate QLocale:: toDate (const QString & string , QLocale::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 参数 (见 dateFormat ()).

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

另请参阅 dateFormat (), toTime (), toDateTime (),和 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.

另请参阅 dateFormat (), toTime (), toDateTime (),和 QDate::fromString ().

[since 5.14] QDate QLocale:: toDate (const QString & string , QLocale::FormatType format , QCalendar cal ) const

这是重载函数。

该函数在 Qt 5.14 引入。

[since 5.14] QDate QLocale:: toDate (const QString & string , const QString & format , QCalendar cal ) const

这是重载函数。

该函数在 Qt 5.14 引入。

QDateTime QLocale:: toDateTime (const QString & string , QLocale::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 参数 (见 dateTimeFormat ()).

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

另请参阅 dateTimeFormat (), toTime (), toDate (),和 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.

注意: 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 . If the string can be parsed and represents an invalid date-time (e.g. in a gap skipped by a time-zone transition), an invalid QDateTime is returned, whose toMSecsSinceEpoch() represents a near-by date-time that is valid. Passing that to fromMSecsSinceEpoch() will produce a valid date-time that isn't faithfully represented by the string parsed.

另请参阅 dateTimeFormat (), toTime (), toDate (),和 QDateTime::fromString ().

[since 5.14] QDateTime QLocale:: toDateTime (const QString & string , QLocale::FormatType format , QCalendar cal ) const

这是重载函数。

该函数在 Qt 5.14 引入。

[since 5.14] QDateTime QLocale:: toDateTime (const QString & string , const QString & format , QCalendar cal ) const

这是重载函数。

该函数在 Qt 5.14 引入。

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

Returns the double represented by the localized string s .

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

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, d == 0
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 == 0
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.

此函数忽略前导和结尾空格。

另请参阅 toFloat (), toInt (),和 toString ().

[since 5.10] double QLocale:: toDouble ( QStringView s , bool * ok = nullptr) const

Returns the double represented by the localized string s .

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

不像 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(u"1234.56", &ok);  // ok == true,  d == 1234.56
d = c.toDouble(u"1,234.56", &ok); // ok == true,  d == 1234.56
d = c.toDouble(u"1234,56", &ok);  // ok == false, d == 0
QLocale german(QLocale::German);
d = german.toDouble(u"1234,56", &ok);  // ok == true,  d == 1234.56
d = german.toDouble(u"1.234,56", &ok); // ok == true,  d == 1234.56
d = german.toDouble(u"1234.56", &ok);  // ok == false, d == 0
d = german.toDouble(u"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.

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toFloat (), toInt (),和 toString ().

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

Returns the float represented by the localized string s .

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

This function does not fall back to the 'C' locale if the string cannot be interpreted in this locale.

此函数忽略前导和结尾空格。

另请参阅 toDouble (), toInt (),和 toString ().

[since 5.10] float QLocale:: toFloat ( QStringView s , bool * ok = nullptr) const

Returns the float represented by the localized string s .

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for any other reason (e.g. underflow).

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toDouble (), toInt (),和 toString ().

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

Returns the int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toUInt () 和 toString ().

[since 5.10] int QLocale:: toInt ( QStringView s , bool * ok = nullptr) const

Returns the int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toUInt () 和 toString ().

[since 5.13] long QLocale:: toLong (const QString & s , bool * ok = nullptr) const

Returns the long int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.13 引入。

另请参阅 toInt (), toULong (), toDouble (),和 toString ().

[since 5.13] long QLocale:: toLong ( QStringView s , bool * ok = nullptr) const

Returns the long int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.13 引入。

另请参阅 toInt (), toULong (), toDouble (),和 toString ().

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

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toInt (), toULongLong (), toDouble (),和 toString ().

[since 5.10] qlonglong QLocale:: toLongLong ( QStringView s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toInt (), toULongLong (), toDouble (),和 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.

另请参阅 QString::toLower ().

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

Returns the short int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toUShort () 和 toString ().

[since 5.10] short QLocale:: toShort ( QStringView s , bool * ok = nullptr) const

Returns the short int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toUShort () 和 toString ().

QString QLocale:: toString ( qlonglong i ) const

返回本地化字符串表示为 i .

另请参阅 toLongLong (), numberOptions (), zeroDigit (),和 positiveSign ().

QString QLocale:: toString ( qulonglong i ) const

这是重载函数。

另请参阅 toULongLong (), numberOptions (), zeroDigit (),和 positiveSign ().

QString QLocale:: toString ( long i ) const

这是重载函数。

另请参阅 toLong ().

QString QLocale:: toString ( ulong i ) const

这是重载函数。

另请参阅 toULong ().

QString QLocale:: toString ( short i ) const

这是重载函数。

另请参阅 toShort ().

QString QLocale:: toString ( ushort i ) const

这是重载函数。

另请参阅 toUShort ().

QString QLocale:: toString ( int i ) const

这是重载函数。

另请参阅 toInt ().

QString QLocale:: toString ( uint i ) const

这是重载函数。

另请参阅 toUInt ().

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

这是重载函数。

Returns a string representing the floating-point number f .

The form of the representation is controlled by the format and precision 参数。

format 默认为 'g' 。它可以是下列任一:

格式 含义
'e' format as [-]9.9e[+|-]999
'E' format as [-]9.9E[+|-]999
'f' format as [-]9.9
'g' 使用 'e' or 'f' format, whichever is more concise
'G' 使用 'E' or 'f' format, whichever is more concise

对于 'e' , 'E' ,和 'f' formats, the precision represents the number of digits after the decimal point. For the 'g' and 'G' formats, the precision represents the maximum number of significant digits (trailing zeroes are omitted). The special precision QLocale::FloatingPointShortest selects the shortest representation that, when read as a number, gets back the original floating-point value. Aside from that, any negative precision is ignored in favor of the default, 6.

对于 'e' , 'f' and 'g' formats, positive infinity is represented as "inf", negative infinity as "-inf" and floating-point NaN (not-a-number) values are represented as "nan". For the 'E' and 'G' formats, "INF" and "NAN" are used instead. This does not vary with locale.

另请参阅 toDouble (), numberOptions (), exponential (), decimalPoint (), zeroDigit (), positiveSign (), percent (), toCurrencyString (), formattedDataSize (),和 QLocale::FloatingPointPrecisionOption .

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

这是重载函数。

Returns a string representing the floating-point number f .

format and precision have the same meanings as described in toString (double, char, int).

另请参阅 toFloat (), toDouble (), numberOptions (), exponential (), decimalPoint (), zeroDigit (), positiveSign (), percent (), toCurrencyString (), formattedDataSize (),和 QLocale::FloatingPointPrecisionOption .

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

返回本地化字符串表示为给定 date 以指定 format 。若 format 是空字符串,返回空字符串。

另请参阅 QDate::toString ().

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

返回本地化字符串表示为给定 time 根据指定 format 。若 format 是空字符串,返回空字符串。

另请参阅 QTime::toString ().

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

返回本地化字符串表示为给定 dateTime 根据指定 format 。若 format 是空字符串,返回空字符串。

另请参阅 QDateTime::toString (), QDate::toString (),和 QTime::toString ().

[since 5.10] QString QLocale:: toString ( QDate date , QStringView format ) const

这是重载函数。

该函数在 Qt 5.10 引入。

QString QLocale:: toString ( QTime time , QStringView format ) const

返回本地化字符串表示为给定 time 根据指定 format 。若 format 是空字符串,返回空字符串。

另请参阅 QTime::toString ().

[since 5.10] QString QLocale:: toString (const QDateTime & dateTime , QStringView format ) const

这是重载函数。

该函数在 Qt 5.10 引入。

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

这是重载函数。

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

返回本地化字符串表示为给定 time 以指定 format (见 timeFormat ()).

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

这是重载函数。

[since 5.14] QString QLocale:: toString ( QDate date , QStringView format , QCalendar cal ) const

返回本地化字符串表示为给定 date 以指定 format , optionally for a specified calendar cal 。若 format 是空字符串,返回空字符串。

该函数在 Qt 5.14 引入。

另请参阅 QDate::toString ().

[since 5.14] QString QLocale:: toString ( QDate date , QLocale::FormatType format , QCalendar cal ) const

返回本地化字符串表示为给定 date 根据指定 format (见 dateFormat ()), optionally for a specified calendar cal .

注意: Some locales may use formats that limit the range of years they can represent.

该函数在 Qt 5.14 引入。

[since 5.14] QString QLocale:: toString (const QDateTime & dateTime , QLocale::FormatType format , QCalendar cal ) const

返回本地化字符串表示为给定 dateTime 根据指定 format (见 dateTimeFormat ()), optionally for a specified calendar cal .

注意: Some locales may use formats that limit the range of years they can represent.

该函数在 Qt 5.14 引入。

[since 5.14] QString QLocale:: toString (const QDateTime & dateTime , QStringView format , QCalendar cal ) const

返回本地化字符串表示为给定 dateTime 根据指定 format , optionally for a specified calendar cal 。若 format 是空字符串,返回空字符串。

该函数在 Qt 5.14 引入。

另请参阅 QDateTime::toString (), QDate::toString (),和 QTime::toString ().

QTime QLocale:: toTime (const QString & string , QLocale::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 参数 (见 timeFormat ()).

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

另请参阅 timeFormat (), toDate (), toDateTime (),和 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.

另请参阅 timeFormat (), toDate (), toDateTime (),和 QTime::fromString ().

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

Returns the unsigned int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toInt () 和 toString ().

[since 5.10] uint QLocale:: toUInt ( QStringView s , bool * ok = nullptr) const

Returns the unsigned int represented by the localized string s .

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toInt () 和 toString ().

[since 5.13] ulong QLocale:: toULong (const QString & s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.13 引入。

另请参阅 toLong (), toInt (), toDouble (),和 toString ().

[since 5.13] ulong QLocale:: toULong ( QStringView s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.13 引入。

另请参阅 toLong (), toInt (), toDouble (),和 toString ().

qulonglong QLocale:: toULongLong (const QString & s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toLongLong (), toInt (), toDouble (),和 toString ().

[since 5.10] qulonglong QLocale:: toULongLong ( QStringView s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toLongLong (), toInt (), toDouble (),和 toString ().

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

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

另请参阅 toShort () 和 toString ().

[since 5.10] ushort QLocale:: toUShort ( QStringView s , bool * ok = nullptr) const

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

若转换失败,函数返回 0。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

此函数忽略前导和结尾空格。

该函数在 Qt 5.10 引入。

另请参阅 toShort () 和 toString ().

QString QLocale:: toUpper (const QString & str ) const

返回大写副本的 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.

另请参阅 QString::toUpper ().

QStringList QLocale:: uiLanguages () const

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

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 对象到 QTranslator::load () 函数。

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

另请参阅 QTranslator and bcp47Name ().

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

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

QString QLocale:: zeroDigit () const

返回此区域设置的 0 数字字符。

另请参阅 toString ().

相关非成员

[since 5.6] size_t qHash (const QLocale & key , size_t seed = 0)

返回哈希值为 key ,使用 seed 做计算种子。

该函数在 Qt 5.6 引入。

bool operator!= (const QLocale & lhs , const QLocale & rhs )

返回 true 若两 QLocale 对象, lhs and rhs 不同;否则返回 false .

注意: 系统区域设置不等于 QLocale 对象构造从其 language (), script () 和 territory (), even if the two agree in all data fields. Nor are two locales with different number options equal.

另请参阅 operator== () 和 setNumberOptions ().

bool operator== (const QLocale & lhs , const QLocale & rhs )

返回 true 若两 QLocale 对象, lhs and rhs 相同;否则返回 false .

注意: 系统区域设置不等于 QLocale 对象构造从其 language (), script () 和 territory (), even if the two agree in all data fields. Nor are two locales with different number options equal.

另请参阅 operator!= () 和 setNumberOptions ().