Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QLatin1String Class

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

Header:#include <QLatin1String>

Note: All functions in this class arereentrant.

Public Functions

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

Detailed Description

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

Many ofQString's member functions are overloaded to acceptconst char * instead ofQString. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such asinsert(),replace(), andindexOf(). These functions are usually optimized to avoid constructing aQString object for theconst char * data. For example, assumingstr is aQString,

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 temporaryQString objects and make a deep copy of the character data.

Applications that defineQT_NO_CAST_FROM_ASCII (as explained in theQString documentation) don't have access toQString'sconst char * API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides theQLatin1String, which is just a very thin wrapper around aconst char *. UsingQLatin1String, 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 usingQString::fromLatin1().

Thanks to theQString(constQLatin1String &) constructor,QLatin1String can be used everywhere aQString is expected. For example:

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

See alsoQString andQLatin1Char.

Member Function Documentation

QLatin1String::QLatin1String(constchar * str)

Constructs aQLatin1String object that storesstr. Note that ifstr is 0, an empty string is created; this case is handled byQString.

The string data isnot copied. The caller must be able to guarantee thatstr will not be deleted or modified as long as theQLatin1String object exists.

See alsolatin1().

constchar * QLatin1String::latin1() const

Returns the Latin-1 string stored in this object.

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

Returns true if this string is not equal to stringother; 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 withQString::localeAwareCompare().

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

This function overloadsoperator!=().

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

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

Returns true if this string is lexically less than theother 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 theQString::localeAwareCompare() function.

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

This is an overloaded function.

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

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

Returns true if this string is lexically less than or equal to stringother; 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 withQString::localeAwareCompare().

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

This is an overloaded function.

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

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

Constructs a copy ofother.

This function was introduced in Qt 4.1.

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

Returns true if this string is equal to stringother; 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 withQString::localeAwareCompare().

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

This is an overloaded function.

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

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

Returns true if this string is lexically greater than stringother; 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 withQString::localeAwareCompare().

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

This is an overloaded function.

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

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

Returns true if this string is lexically greater than or equal to stringother; 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 withQString::localeAwareCompare().

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

This is an overloaded function.

Theother const char pointer is converted to aQString using theQString::fromAscii() function.

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

This function was introduced in Qt 4.3.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp