|  | Home · All Classes · Modules

# QLatin1String Class Reference
[QtCore module]

The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal. 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)
- object __repr__ (self)

## Detailed Description

This class can be pickled.

The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.

Many of QString's member functions are overloaded to accept `const char *` instead of QString. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as insert(), replace(), and indexOf(). These functions are usually optimized to avoid constructing a QString object for the `const char *` data. For example, assuming `str` is a QString,

     if (str == "auto" || str == "extern"
             || str == "static" || str == "register") {
         ...
     }

is much faster than

     if (str == QString("auto") || str == QString("extern")
             || str == QString("static") || str == QString("register")) {
         ...
     }

because it doesn't construct four temporary QString objects and make a deep copy of the character data.

Applications that define `QT_NO_CAST_FROM_ASCII` (as explained in the QString documentation) don't have access to QString's `const char *` API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides the QLatin1String, which is just a very thin wrapper around a `const char *`. Using QLatin1String, the example code above becomes

     if (str == QLatin1String("auto")
             || str == QLatin1String("extern")
             || str == QLatin1String("static")
             || str == QLatin1String("register") {
         ...
     }

This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString.fromLatin1().

Thanks to the QString(const QLatin1String &) constructor, QLatin1String can be used everywhere a QString is expected. For example:

     QLabel *label = new QLabel(QLatin1String("MOD"), this);

## Method Documentation

### QLatin1String.__init__ (self, str s)

Constructs a QLatin1String object that stores str. Note that if str is 0, an empty string is created; this case is handled by QString.

The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1String object exists.

See also latin1().

### QLatin1String.__init__ (self, QLatin1String)

### str QLatin1String.latin1 (self)

Returns the Latin-1 string stored in this object.

### bool QLatin1String.__eq__ (self, QString s)

### bool QLatin1String.__eq__ (self, QLatin1String s2)

### bool QLatin1String.__eq__ (self, QStringRef s2)

### bool QLatin1String.__ge__ (self, QString s)

### bool QLatin1String.__ge__ (self, QLatin1String s2)

### bool QLatin1String.__gt__ (self, QString s)

### bool QLatin1String.__gt__ (self, QLatin1String s2)

### bool QLatin1String.__le__ (self, QString s)

### bool QLatin1String.__le__ (self, QLatin1String s2)

### bool QLatin1String.__lt__ (self, QString s)

### bool QLatin1String.__lt__ (self, QLatin1String s2)

### bool QLatin1String.__ne__ (self, QString s)

### bool QLatin1String.__ne__ (self, QLatin1String s2)

### bool QLatin1String.__ne__ (self, QStringRef s2)

### object QLatin1String.__repr__ (self)