Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QLatin1String Class Reference
[QtCore module]

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

 #include <QLatin1String>

Note: All the functions in this class are reentrant.

Public Functions


Detailed Description

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

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 and QLatin1Char.


Member Function Documentation

QLatin1String::QLatin1String ( const char * str )

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

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

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

This is an overloaded member function, provided for convenience.

The other const char pointer is converted to a QLatin1String 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.

This function was introduced in 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() function.

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

This is an overloaded member function, provided for convenience.

The other const char pointer is converted to a QLatin1String 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.

This function was introduced in Qt 4.3.

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

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

This is an overloaded member function, provided for convenience.

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.

This function was introduced in Qt 4.3.

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

Constructs a copy of other.

This function was introduced in Qt 4.1.

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

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

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

This is an overloaded member function, provided for convenience.

The other const char pointer is converted to a QLatin1String 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.

This function was introduced in Qt 4.3.

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

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

This is an overloaded member function, provided for convenience.

The other const char pointer is converted to a QLatin1String 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.

This function was introduced in Qt 4.3.

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

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

This is an overloaded member function, provided for convenience.

The other const char pointer is converted to a QLatin1String 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.

This function was introduced in Qt 4.3.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année

Le Qt Labs au hasard

Logo

QLocale : à propos du temps (et des dates, et des langues, et des...)

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web