QLatin1String 类

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

头: #include <QLatin1String>

注意: 此类的所有函数 可重入 .

公共函数

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

详细描述

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

很多 QString 's member functions are overloaded to accept const char * 而不是 QString . This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as insert() , replace() ,和 indexOf() . These functions are usually optimized to avoid constructing a QString 对象为 const char * data. For example, assuming str 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 * 。使用 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);
					

另请参阅 QString and QLatin1Char .

成员函数文档编制

QLatin1String:: QLatin1String (const char * str )

构造 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.

另请参阅 latin1 ().

const char * QLatin1String:: latin1 () const

Returns the Latin-1 string stored in this object.

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

Returns true if this string is not equal to string other ;否则返回 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 ().

bool QLatin1String:: operator!= (const char * other ) const

此函数重载 operator!= ().

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。

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

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 () 函数。

bool QLatin1String:: operator< (const char * other ) const

这是重载函数。

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。

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

Returns true if this string is lexically less than or equal to string other ;否则返回 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 ().

bool QLatin1String:: operator<= (const char * other ) const

这是重载函数。

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。

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

构造副本为 other .

该函数在 Qt 4.1 引入。

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

Returns true if this string is equal to string other ;否则返回 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 ().

bool QLatin1String:: operator== (const char * other ) const

这是重载函数。

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。

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

Returns true if this string is lexically greater than string other ;否则返回 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 ().

bool QLatin1String:: operator> (const char * other ) const

这是重载函数。

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。

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

Returns true if this string is lexically greater than or equal to string other ;否则返回 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 ().

bool QLatin1String:: operator>= (const char * other ) const

这是重载函数。

The other const char pointer is converted to a QString 使用 QString::fromAscii () 函数。

可以禁用此运算符通过定义 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.

该函数在 Qt 4.3 引入。