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  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QWeakPointer Class Reference
[QtCore module]

The QWeakPointer class holds a weak reference to a shared pointer More...

 #include <QWeakPointer>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.5.

Public Functions

Related Non-Members

  • QSharedPointer<X> qSharedPointerCast ( const QWeakPointer<T> & other )
  • QSharedPointer<X> qSharedPointerConstCast ( const QWeakPointer<T> & other )
  • QSharedPointer<X> qSharedPointerDynamicCast ( const QWeakPointer<T> & other )
  • QWeakPointer<X> qWeakPointerCast ( const QWeakPointer<T> & other )
  • bool operator!= ( const QWeakPointer<T> & ptr1, const QSharedPointer<X> & ptr2 )
  • bool operator!= ( const QSharedPointer<T> & ptr1, const QWeakPointer<X> & ptr2 )
  • bool operator== ( const QWeakPointer<T> & ptr1, const QSharedPointer<X> & ptr2 )
  • bool operator== ( const QSharedPointer<T> & ptr1, const QWeakPointer<X> & ptr2 )

Detailed Description

The QWeakPointer class holds a weak reference to a shared pointer

The QWeakPointer is an automatic weak reference to a pointer in C++. It cannot be used to dereference the pointer directly, but it can be used to verify if the pointer has been deleted or not in another context.

QWeakPointer objects can only be created by assignment from a QSharedPointer.

To access the pointer that QWeakPointer is tracking, you must first create a QSharedPointer object and verify if the pointer is null or not.

See also QSharedPointer.


Member Function Documentation

QWeakPointer::QWeakPointer ()

Creates a QWeakPointer that points to nothing.

QWeakPointer::QWeakPointer ( const QWeakPointer<T> & other )

Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

QWeakPointer::QWeakPointer ( const QSharedPointer<T> & other )

Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

QWeakPointer::~QWeakPointer ()

Destroys this QWeakPointer object. The pointer referenced by this object will not be deleted.

void QWeakPointer::clear ()

Clears this QWeakPointer object, dropping the reference that it may have had to the pointer.

bool QWeakPointer::isNull () const

Returns true if this object is holding a reference to a null pointer.

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from false to true from one call to the next.

QSharedPointer<T> QWeakPointer::toStrongRef () const

Promotes this weak reference to a strong one and returns a QSharedPointer object holding that reference.

QWeakPointer::operator bool () const

Returns true if this object is not null. This function is suitable for use in if-constructs, like:

 if (weakref) { ... }

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from true to false from one call to the next.

See also isNull().

bool QWeakPointer::operator! () const

Returns true if this object is null. This function is suitable for use in if-constructs, like:

 if (!weakref) { ... }

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from false to true from one call to the next.

See also isNull().

QWeakPointer<T> QWeakPointer::operator= ( const QWeakPointer<T> & other )

Makes this object share other's pointer. The current pointer reference is discarded but is not deleted.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

QWeakPointer<T> QWeakPointer::operator= ( const QSharedPointer<T> & other )

Makes this object share other's pointer. The current pointer reference is discarded but is not deleted.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.


Related Non-Members

QSharedPointer<X> qSharedPointerCast ( const QWeakPointer<T> & other )

Returns a shared pointer to the pointer held by other, cast to type X. The types T and X must belong to one hierarchy for the static_cast to succeed.

The other object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function returns a null QSharedPointer.

Note that X must have the same cv-qualifiers (const and volatile) that T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.

See also QWeakPointer::toStrongRef(), qSharedPointerDynamicCast(), and qSharedPointerConstCast().

QSharedPointer<X> qSharedPointerConstCast ( const QWeakPointer<T> & other )

Returns a shared pointer to the pointer held by other, cast to type X. The types T and X must belong to one hierarchy for the const_cast to succeed. The const and volatile differences between T and X are ignored.

The other object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function returns a null QSharedPointer.

See also QWeakPointer::toStrongRef(), qSharedPointerCast(), and qSharedPointerDynamicCast().

QSharedPointer<X> qSharedPointerDynamicCast ( const QWeakPointer<T> & other )

Returns a shared pointer to the pointer held by other, using a dynamic cast to type X to obtain an internal pointer of the appropriate type. If the dynamic_cast fails, the object returned will be null.

The other object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function also returns a null QSharedPointer.

Note that X must have the same cv-qualifiers (const and volatile) that T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.

See also QWeakPointer::toStrongRef(), qSharedPointerCast(), and qSharedPointerConstCast().

QWeakPointer<X> qWeakPointerCast ( const QWeakPointer<T> & other )

Returns a weak pointer to the pointer held by other, cast to type X. The types T and X must belong to one hierarchy for the static_cast to succeed.

Note that X must have the same cv-qualifiers (const and volatile) that T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.

bool operator!= ( const QWeakPointer<T> & ptr1, const QSharedPointer<X> & ptr2 )

Returns true if the pointer referenced by ptr1 is not the same pointer as that referenced by ptr2.

If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.

bool operator!= ( const QSharedPointer<T> & ptr1, const QWeakPointer<X> & ptr2 )

Returns true if the pointer referenced by ptr1 is not the same pointer as that referenced by ptr2.

If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.

bool operator== ( const QWeakPointer<T> & ptr1, const QSharedPointer<X> & ptr2 )

Returns true if the pointer referenced by ptr1 is the same pointer as that referenced by ptr2.

If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.

bool operator== ( const QSharedPointer<T> & ptr1, const QWeakPointer<X> & ptr2 )

Returns true if the pointer referenced by ptr1 is the same pointer as that referenced by ptr2.

If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.

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 64
  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. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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.5
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