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  · 

QStringRef Class Reference
[QtCore module]

The QStringRef class provides a thin wrapper around QString substrings. More...

 #include <QStringRef>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.3.

Public Functions

Related Non-Members

  • bool operator< ( const QStringRef & s1, const QStringRef & s2 )
  • bool operator<= ( const QStringRef & s1, const QStringRef & s2 )
  • bool operator== ( const QStringRef & s1, const QStringRef & s2 )
  • bool operator== ( const QString & s1, const QStringRef & s2 )
  • bool operator== ( const QLatin1String & s1, const QStringRef & s2 )
  • bool operator> ( const QStringRef & s1, const QStringRef & s2 )
  • bool operator>= ( const QStringRef & s1, const QStringRef & s2 )

Detailed Description

The QStringRef class provides a thin wrapper around QString substrings.

QStringRef provides a read-only subset of the QString API.

A string reference explicitly references a portion of a string() with a given size(), starting at a specific position(). Calling toString() returns a copy of the data as a real QString instance.

This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing QString instances. QStringRef avoids the memory allocation and reference counting overhead of a standard QString by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.

For most users, there are no semantic benefits to using QStringRef instead of QString since QStringRef requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.

Warning: A QStringRef is only valid as long as the referenced string exists. If the original string is deleted, the string reference points to an invalid memory location.

We suggest that you only use this class in stable code where profiling has clearly identified that performance improvements can be made by replacing standard string operations with the optimized substring handling provided by this class.

See also Implicitly Shared Classes.


Member Function Documentation

QStringRef::QStringRef ()

Constructs an empty string reference.

QStringRef::QStringRef ( const QString * string, int position, int length )

Constructs a string reference to the range of characters in the given string specified by the starting position and length in characters.

Warning: This function exists to improve performance as much as possible, and performs no bounds checking. For program correctness, position and length must describe a valid substring of string.

This means that the starting position must be positive or 0 and smaller than string's length, and length must be positive or 0 but smaller than the string's length minus the starting position; i.e, 0 <= position < string->length() and 0 <= length <= string->length() - position must both be satisfied.

QStringRef::QStringRef ( const QString * string )

Constructs a string reference to the given string.

QStringRef::QStringRef ( const QStringRef & other )

Constructs a copy of the other string reference.

QStringRef::~QStringRef ()

Destroys the string reference.

Since this class is only used to refer to string data, and does not take ownership of it, no memory is freed when instances are destroyed.

QStringRef QStringRef::appendTo ( QString * string ) const

Appends the string reference to string, and returns a new reference to the combined string data.

const QChar QStringRef::at ( int position ) const

Returns the character at the given index position in the string reference.

The position must be a valid index position in the string (i.e., 0 <= position < size()).

void QStringRef::clear ()

Clears the contents of the string reference by making it null and empty.

See also isEmpty() and isNull().

const QChar * QStringRef::constData () const

Same as unicode().

int QStringRef::count () const

Returns the number of characters in this string.

See also position().

const QChar * QStringRef::data () const

Same as unicode().

bool QStringRef::isEmpty () const

Returns true if the string reference has no characters; otherwise returns false.

A string reference is empty if its size is zero.

See also size().

bool QStringRef::isNull () const

Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true.

See also size().

int QStringRef::length () const

Returns the number of characters in this substring.

See also position().

int QStringRef::position () const

Returns the starting position in the referenced string that is referred to by the string reference.

See also size() and string().

int QStringRef::size () const

Returns the number of characters referred to by the string reference.

See also position() and string().

const QString * QStringRef::string () const

Returns a pointer to the string referred to by the string reference, or 0 if it does not reference a string.

See also unicode().

QString QStringRef::toString () const

Returns a copy of the string reference as a QString object.

If the string reference is not a complete reference of the string (meaning that position() is 0 and size() equals string()->size()), this function will allocate a new string to return.

See also string().

const QChar * QStringRef::unicode () const

Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not null-terminated unless the string reference includes the string's null terminator.

See also string().

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

Assigns the other string reference to this string reference, and returns the result.

QStringRef & QStringRef::operator= ( const QString * string )

This is an overloaded member function, provided for convenience.

Constructs a string reference to the given string and assigns it to this string reference, returning the result.


Related Non-Members

bool operator< ( const QStringRef & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string reference s1 is lexically less than string reference s2; 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 operator<= ( const QStringRef & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string reference s1 is lexically less than or equal to string reference s2; 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 operator== ( const QStringRef & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string reference s1 is lexically equal to string reference s2; otherwise returns false.

bool operator== ( const QString & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.

bool operator== ( const QLatin1String & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.

bool operator> ( const QStringRef & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string reference s1 is lexically greater than string reference s2; 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 operator>= ( const QStringRef & s1, const QStringRef & s2 )

This is an overloaded member function, provided for convenience.

Returns true if string reference s1 is lexically greater than or equal to string reference s2; 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.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 45
  4. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 6
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Quarterly au hasard

Logo

Conserver la réactivité de l'IHM

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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.3
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