Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QLatin1String Class Reference

List of all members.


Detailed Description

The QLatin1String class provides a thin wrapper around an 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,

doc/src/snippets/code/src_corelib_tools_qstring.cpp 3

is much faster than

doc/src/snippets/code/src_corelib_tools_qstring.cpp 4

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

doc/src/snippets/code/src_corelib_tools_qstring.cpp 5

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:

doc/src/snippets/code/src_corelib_tools_qstring.cpp 6

See also:
QString, QLatin1Char

Definition at line 605 of file qstring.h.


Public Member Functions

const char * latin1 () const
QT_ASCII_CAST_WARN bool operator!= (const char *s) const
bool operator!= (const QString &s) const
QT_ASCII_CAST_WARN bool operator< (const char *s) const
bool operator< (const QString &s) const
QT_ASCII_CAST_WARN bool operator<= (const char *s) const
bool operator<= (const QString &s) const
QLatin1Stringoperator= (const QLatin1String &other)
QT_ASCII_CAST_WARN bool operator== (const char *s) const
bool operator== (const QString &s) const
QT_ASCII_CAST_WARN bool operator> (const char *s) const
bool operator> (const QString &s) const
QT_ASCII_CAST_WARN bool operator>= (const char *s) const
bool operator>= (const QString &s) const
 QLatin1String (const char *s)

Private Attributes

const char * chars

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index