Qt 4.8
Public Functions | Properties | List of all members
QLatin1String Class Reference

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

#include <qstring.h>

Public Functions

const char * latin1 () const
 Returns the Latin-1 string stored in this object. More...
 
bool operator!= (const QString &s) const
 Returns true if this string is not equal to string other; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator!= (const char *s) const
 
bool operator< (const QString &s) const
 Returns true if this string is lexically less than the other string; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator< (const char *s) const
 
bool operator<= (const QString &s) const
 Returns true if this string is lexically less than or equal to string other; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator<= (const char *s) const
 
QLatin1Stringoperator= (const QLatin1String &other)
 Constructs a copy of other. More...
 
bool operator== (const QString &s) const
 Returns true if this string is equal to string other; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator== (const char *s) const
 
bool operator> (const QString &s) const
 Returns true if this string is lexically greater than string other; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator> (const char *s) const
 
bool operator>= (const QString &s) const
 Returns true if this string is lexically greater than or equal to string other; otherwise returns false. More...
 
QT_ASCII_CAST_WARN bool operator>= (const char *s) const
 
 QLatin1String (const char *s)
 Constructs a QLatin1String object that stores str. More...
 

Properties

const char * chars
 

Detailed Description

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

Note
This class or function is reentrant.

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);
See also
QString, QLatin1Char

Definition at line 654 of file qstring.h.

Constructors and Destructors

◆ QLatin1String()

QLatin1String::QLatin1String ( const char *  str)
inlineexplicit

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

Definition at line 657 of file qstring.h.

657 : chars(s) {}
const char * chars
Definition: qstring.h:689

Functions

◆ latin1()

const char * QLatin1String::latin1 ( ) const
inline

◆ operator!=() [1/2]

bool QLatin1String::operator!= ( const QString other) const
inline

Returns true if this string is not equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 665 of file qstring.h.

666  { return s != *this; }

◆ operator!=() [2/2]

QT_ASCII_CAST_WARN bool QLatin1String::operator!= ( const char *  s) const
inline

Definition at line 678 of file qstring.h.

679  { return QString::fromAscii(s) != *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

◆ operator<() [1/2]

bool QLatin1String::operator< ( const QString other) const
inline

Returns true if this string is lexically less than the other string; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function.

Definition at line 669 of file qstring.h.

670  { return s > *this; }

◆ operator<() [2/2]

bool QLatin1String::operator< ( const char *  other) const
inline
Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The other const char pointer is converted to a QString using the QString::fromAscii() function.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

Definition at line 680 of file qstring.h.

681  { return QString::fromAscii(s) > *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

◆ operator<=() [1/2]

bool QLatin1String::operator<= ( const QString other) const
inline

Returns true if this string is lexically less than or equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 673 of file qstring.h.

674  { return s >= *this; }

◆ operator<=() [2/2]

bool QLatin1String::operator<= ( const char *  other) const
inline
Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The other const char pointer is converted to a QString using the QString::fromAscii() function.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

Definition at line 684 of file qstring.h.

685  { return QString::fromAscii(s) >= *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

◆ operator=()

QLatin1String & QLatin1String::operator= ( const QLatin1String other)
inline

Constructs a copy of other.

Since
4.1

Definition at line 658 of file qstring.h.

659  { chars = other.chars; return *this; }
const char * chars
Definition: qstring.h:689

◆ operator==() [1/2]

bool QLatin1String::operator== ( const QString other) const
inline

Returns true if this string is equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 663 of file qstring.h.

664  { return s == *this; }

◆ operator==() [2/2]

bool QLatin1String::operator== ( const char *  other) const
inline
Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The other const char pointer is converted to a QString using the QString::fromAscii() function.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

Definition at line 676 of file qstring.h.

677  { return QString::fromAscii(s) == *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

◆ operator>() [1/2]

bool QLatin1String::operator> ( const QString other) const
inline

Returns true if this string is lexically greater than string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 667 of file qstring.h.

668  { return s < *this; }

◆ operator>() [2/2]

bool QLatin1String::operator> ( const char *  other) const
inline
Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The other const char pointer is converted to a QString using the QString::fromAscii() function.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

Definition at line 682 of file qstring.h.

683  { return QString::fromAscii(s) < *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

◆ operator>=() [1/2]

bool QLatin1String::operator>= ( const QString other) const
inline

Returns true if this string is lexically greater than or equal to string other; otherwise returns false.

The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare().

Definition at line 671 of file qstring.h.

672  { return s <= *this; }

◆ operator>=() [2/2]

bool QLatin1String::operator>= ( const char *  other) const
inline
Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The other const char pointer is converted to a QString using the QString::fromAscii() function.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

Definition at line 686 of file qstring.h.

687  { return QString::fromAscii(s) <= *this; }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276

Properties

◆ chars

const char* QLatin1String::chars
private

Definition at line 689 of file qstring.h.

Referenced by operator=().


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