QLatin1String 類

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

頭: #include <QLatin1String>
qmake: QT += core

注意: 此類的所有函數 可重入 .

公共函數

QLatin1String ()
QLatin1String (const char * str )
QLatin1String (const char * str , int size )
QLatin1String (const QByteArray & str )
QLatin1Char at (int pos ) const
const char * data () const
const char * latin1 () const
QLatin1String left (int length ) const
QLatin1String mid (int start ) const
QLatin1String mid (int start , int length ) const
QLatin1String right (int length ) const
int size () const
bool operator!= (const QString & other ) const
bool operator!= (const char * other ) const
bool operator!= (const QByteArray & other ) const
bool operator< (const QString & other ) const
bool operator< (const char * other ) const
bool operator< (const QByteArray & other ) const
bool operator<= (const QString & other ) const
bool operator<= (const char * other ) const
bool operator<= (const QByteArray & other ) const
bool operator== (const QString & other ) const
bool operator== (const char * other ) const
bool operator== (const QByteArray & other ) const
bool operator> (const QString & other ) const
bool operator> (const char * other ) const
bool operator> (const QByteArray & other ) const
bool operator>= (const QString & other ) const
bool operator>= (const char * other ) const
bool operator>= (const QByteArray & other ) const
QLatin1Char operator[] (int pos ) const
bool operator!= (QLatin1String s1 , QLatin1String s2 )
bool operator< (QLatin1String s1 , QLatin1String s2 )
bool operator<= (QLatin1String s1 , QLatin1String s2 )
bool operator== (QLatin1String s1 , QLatin1String s2 )
bool operator> (QLatin1String s1 , QLatin1String s2 )
bool operator>= (QLatin1String s1 , QLatin1String s2 )

詳細描述

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 ( QLatin1String ) constructor, QLatin1String can be used everywhere a QString is expected. For example:

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

注意: If the function you're calling with a QLatin1String argument isn't actually overloaded to take QLatin1String , the implicit conversion to QString will trigger a memory allocation, which is usually what you want to avoid by using QLatin1String in the first place. In those cases, using QStringLiteral may be the better option.

另請參閱 QString , QLatin1Char ,和 QStringLiteral .

成員函數文檔編製

QLatin1String:: QLatin1String ()

構造 QLatin1String object that stores a nullptr.

該函數在 Qt 5.6 引入。

QLatin1String:: QLatin1String (const char * str )

構造 QLatin1String object that stores str .

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

QLatin1String:: QLatin1String (const char * str , int size )

構造 QLatin1String object that stores str with size .

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

QLatin1String:: QLatin1String (const QByteArray & str )

構造 QLatin1String object that stores str .

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

QLatin1Char QLatin1String:: at ( int pos ) const

返迴字符位於位置 pos 在此對象。

注意: This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size ().

該函數在 Qt 5.8 引入。

另請參閱 operator[] ().

const char *QLatin1String:: data () const

Returns the Latin-1 string stored in this object.

const char *QLatin1String:: latin1 () const

Returns the Latin-1 string stored in this object.

QLatin1String QLatin1String:: left ( int length ) const

返迴子字符串長度 length starting at position 0 in this object.

注意: This function performs no error checking. The behavior is undefined when length < 0 or length > size ().

該函數在 Qt 5.8 引入。

另請參閱 mid () 和 right ().

QLatin1String QLatin1String:: mid ( int start ) const

Returns the substring starting at position start in this object, and extending to the end of the string.

注意: This function performs no error checking. The behavior is undefined when start < 0 or start > size ().

該函數在 Qt 5.8 引入。

另請參閱 left () 和 right ().

QLatin1String QLatin1String:: mid ( int start , int length ) const

這是重載函數。

返迴子字符串長度 length 起始於位置 start 在此對象。

注意: This function performs no error checking. The behavior is undefined when start < 0, length < 0, or start + length > size ().

該函數在 Qt 5.8 引入。

另請參閱 left () 和 right ().

返迴子字符串長度 length 起始於位置 size () - length 在此對象。

注意: This function performs no error checking. The behavior is undefined when length < 0 or length > size ().

該函數在 Qt 5.8 引入。

另請參閱 mid () 和 left ().

int QLatin1String:: size () const

Returns the size of the Latin-1 string stored in this object.

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

此函數重載 operator!= ().

The other byte array is converted to a QString 使用 QString::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 5.0 引入。

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

這是重載函數。

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

可以禁用此運算符通過定義 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 5.0 引入。

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

這是重載函數。

The other array is converted to a QString 使用 QString::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 5.0 引入。

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

這是重載函數。

The other byte array is converted to a QString 使用 QString::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 5.0 引入。

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

這是重載函數。

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

可以禁用此運算符通過定義 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 5.0 引入。

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

返迴 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::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 QByteArray & other ) const

這是重載函數。

The other array is converted to a QString 使用 QString::fromUtf8 () 函數。

可以禁用此運算符通過定義 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 5.0 引入。

QLatin1Char QLatin1String:: operator[] ( int pos ) const

返迴字符位於位置 pos 在此對象。

注意: This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size ().

該函數在 Qt 5.8 引入。

另請參閱 at ().

相關非成員

bool operator!= ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 is lexically unequal to string s2 ;否則返迴 false .

bool operator< ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 is lexically smaller than string s2 ;否則返迴 false .

bool operator<= ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 is lexically smaller than or equal to string s2 ;否則返迴 false .

bool operator== ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 is lexically equal to string s2 ;否則返迴 false .

bool operator> ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 詞法上大於字符串 s2 ;否則返迴 false .

bool operator>= ( QLatin1String s1 , QLatin1String s2 )

返迴 true 若字符串 s1 詞法上大於等於字符串 s2 ;否則返迴 false .