IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QLatin1String Class

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

All functions in this class are https://.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QLatin1String Class▲

  • Header: QLatin1String

  • qmake: QT += core

  • Group: QLatin1String is part of string-processing

Detailed Description▲

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,

 
Sélectionnez
if (str == "auto" || str == "extern"
        || str == "static" || str == "register") {
    ...
}

is much faster than

 
Sélectionnez
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 https://, which is just a very thin wrapper around a const char *. Using https://, the example code above becomes

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

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

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

See Also▲

See also https://, https://, https://, https://

Member Type Documentation▲

 

[alias, since 5.10] QLatin1String::difference_type▲

Alias for int. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.10.

[alias, since 5.10] QLatin1String::size_type▲

Alias for int. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.10.

Member Function Documentation▲

 

[default, since 5.6] QLatin1String::QLatin1String()▲

Constructs a https:// object that stores a nullptr.

This function was introduced in Qt 5.6.

[default] QLatin1String::QLatin1String(const char *str)▲

Constructs a https:// 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 https:// object exists.

See Also▲

See also latin1()

[default] QLatin1String::QLatin1String(const char *str, int size)▲

Constructs a https:// 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 https:// object exists.

See Also▲

See also latin1()

[default, since 5.10] QLatin1String::QLatin1String(const char *first, const char *last)▲

Constructs a https:// object that stores first with length (last - first).

The range [first,last) must remain valid for the lifetime of this Latin-1 string object.

Passing nullptr as first is safe if last is nullptr, too, and results in a null Latin-1 string.

The behavior is undefined if last precedes first, first is nullptr and last is not, or if last - first > INT_MAX.

This function was introduced in Qt 5.10.

[default] QLatin1String::QLatin1String(const QByteArray &str)▲

Constructs a https:// 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 https:// object exists.

See Also▲

See also latin1()

[since 5.10] int QLatin1String::rbegin() const▲

Returns a const https:// reverse iterator pointing to the first character in the string, in reverse order.

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also▲

See also rend(), crbegin(), begin()

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

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

[since 4.3] bool QLatin1String::operator!=(const char *other) const▲

This function overloads https://().

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator!=(const QByteArray &other) const▲

This function overloads https://().

The other byte array is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

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

[since 4.3] bool QLatin1String::operator<(const char *other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator<(const QByteArray &other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

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

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

[since 4.3] bool QLatin1String::operator<=(const char *other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator<=(const QByteArray &other) const▲

This is an overloaded function.

The other array is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

[since 4.3] bool QLatin1String::operator==(const char *other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator==(const QByteArray &other) const▲

This is an overloaded function.

The other byte array is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

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

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

[since 4.3] bool QLatin1String::operator>(const char *other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator>(const QByteArray &other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

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

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

[since 4.3] bool QLatin1String::operator>=(const char *other) const▲

This is an overloaded function.

The other const char pointer is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 4.3.

See Also▲

See also https://

[since 5.0] bool QLatin1String::operator>=(const QByteArray &other) const▲

This is an overloaded function.

The other array is converted to a QString using the QString::fromUtf8() 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.

This function was introduced in Qt 5.0.

See Also▲

See also https://

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.