QLatin1String Class Reference

[QtCore module]

该QLatin1String类提供了简单包装的一个US-ASCII/Latin-1编码的字符串文字。More…

Methods

  • __init__ (self, str s)
  • __init__ (self, QLatin1String)
  • str latin1 (self)

Special Methods

  • bool __eq__ (self, QString s)
  • bool __eq__ (self, QLatin1String s2)
  • bool __eq__ (self, QStringRef s2)
  • bool __ge__ (self, QString s)
  • bool __ge__ (self, QLatin1String s2)
  • bool __gt__ (self, QString s)
  • bool __gt__ (self, QLatin1String s2)
  • bool __le__ (self, QString s)
  • bool __le__ (self, QLatin1String s2)
  • bool __lt__ (self, QString s)
  • bool __lt__ (self, QLatin1String s2)
  • bool __ne__ (self, QString s)
  • bool __ne__ (self, QLatin1String s2)
  • bool __ne__ (self, QStringRef s2)
  • str __repr__ (self)

Detailed Description

这个类可以醃制。

该QLatin1String类提供了简单包装的一个US-ASCII/Latin-1编码的字符串文字。

许多QString的成员函数重载接受const char *而不是QString。这包括拷贝构造函数,赋值操作符,比较操作符,以及其他各种功能,如insert()replace()indexOf()。这些功能通常是优化,以避免建设QString为对象const char *数据。例如,假设strQString

  1. if (str == "auto" || str == "extern"
  2. || str == "static" || str == "register") {
  3. ...
  4. }

是不是快很多

  1. if (str == [QString]($docs-qstring.html)("auto") || str == [QString]($docs-qstring.html)("extern")
  2. || str == [QString]($docs-qstring.html)("static") || str == [QString]($docs-qstring.html)("register")) {
  3. ...
  4. }

因为它没有构造四个临时QString对象,使字符数据的深层副本。

定义应用程序QT_NO_CAST_FROM_ASCII(在所说明QString文档)不具有访问QStringconst char *API。提供指定固定的Latin-1的字符串的有效方式, Qt提供了QLatin1String ,这是围绕一个只是一个非常薄的包装const char *。使用QLatin1String ,上面的例子代码变得

  1. if (str == QLatin1String("auto")
  2. || str == QLatin1String("extern")
  3. || str == QLatin1String("static")
  4. || str == QLatin1String("register") {
  5. ...
  6. }

这是一个有点长一些,但它提供了完全相同的利益作为代码的第一个版本,并且比使用转换Latin-1的字符串更快QString.fromLatin1( ) 。

多亏了QString(常量QLatin1String & )构造函数, QLatin1String可以到处使用QString预计。例如:

  1. [QLabel](qlabel.html) *label = new [QLabel](qlabel.html)(QLatin1String("MOD"), this);

Method Documentation

  1. QLatin1String.__init__ (self, str s)

构造一个QLatin1String对象,它存储str。注意,如果str为0时,将创建一个空字符串,这种情况下是通过处理QString

字符串数据是not复制。调用者必须能够保证str也不会被删除或修改,只要该QLatin1String对象存在。

See also latin1( ) 。

  1. QLatin1String.__init__ (self, QLatin1String)
  1. str QLatin1String.latin1 (self)

返回存储在此对象中的Latin-1的字符串。

  1. bool QLatin1String.__eq__ (self, QString s)
  1. bool QLatin1String.__eq__ (self, QLatin1String s2)
  1. bool QLatin1String.__eq__ (self, QStringRef s2)
  1. bool QLatin1String.__ge__ (self, QString s)
  1. bool QLatin1String.__ge__ (self, QLatin1String s2)
  1. bool QLatin1String.__gt__ (self, QString s)
  1. bool QLatin1String.__gt__ (self, QLatin1String s2)
  1. bool QLatin1String.__le__ (self, QString s)
  1. bool QLatin1String.__le__ (self, QLatin1String s2)
  1. bool QLatin1String.__lt__ (self, QString s)
  1. bool QLatin1String.__lt__ (self, QLatin1String s2)
  1. bool QLatin1String.__ne__ (self, QString s)
  1. bool QLatin1String.__ne__ (self, QLatin1String s2)
  1. bool QLatin1String.__ne__ (self, QStringRef s2)
  1. str QLatin1String.__repr__ (self)