diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-06-25 15:22:53 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-02 11:48:19 (GMT) |
commit | a32019f4c2f56a84172bde739d7ea174be0db381 (patch) | |
tree | 579a815d43164fbd4003c0fb4c38aaf366d07c9c /src/corelib/tools/qsharedpointer.cpp | |
parent | 0b757d0c1b6f64d17086621ec692369d37fd62fc (diff) | |
download | Qt-a32019f4c2f56a84172bde739d7ea174be0db381.zip Qt-a32019f4c2f56a84172bde739d7ea174be0db381.tar.gz Qt-a32019f4c2f56a84172bde739d7ea174be0db381.tar.bz2 |
Add qobject_cast for QSharedPointer.
This obviously only works for classes that derive from QObject. And
you must remember that QSharedPointer controls the QObject's lifetime,
not the QObject parent-child relationship.
Reviewed-by: dt
Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index ba62ce1..71bf318 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -340,6 +340,23 @@ */ /*! + \fn QSharedPointer<X> QSharedPointer::objectCast() const + + Performs a \ref qobject_cast from this pointer's type to \tt X and + returns a QSharedPointer that shares the reference. If this + function is used to up-cast, then QSharedPointer will perform a \tt + qobject_cast, which means that if the object being pointed by this + QSharedPointer is not of type \tt X, the returned object will be + null. + + Note: the template type \c X must have the same const and volatile + qualifiers as the template of this object, or the cast will + fail. Use constCast() if you need to drop those qualifiers. + + \sa qSharedPointerObjectCast() +*/ + +/*! \fn QWeakPointer<T> QSharedPointer::toWeakRef() const Returns a weak reference object that shares the pointer referenced @@ -718,6 +735,45 @@ */ /*! + \fn QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &other) + \relates QSharedPointer + + Returns a shared pointer to the pointer held by \a other, using a + \ref qobject_cast to type \tt X to obtain an internal pointer of the + appropriate type. If the \tt qobject_cast fails, the object + returned will be null. + + Note that \tt X must have the same cv-qualifiers (\tt const and + \tt volatile) that \tt T has, or the code will fail to + compile. Use qSharedPointerConstCast to cast away the constness. + + \sa QSharedPointer::objectCast(), qSharedPointerCast(), qSharedPointerConstCast() +*/ + +/*! + \fn QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &other) + \relates QSharedPointer + \relates QWeakPointer + + Returns a shared pointer to the pointer held by \a other, using a + \ref qobject_cast to type \tt X to obtain an internal pointer of the + appropriate type. If the \tt qobject_cast fails, the object + returned will be null. + + The \a 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 \tt X must have the same cv-qualifiers (\tt const and + \tt volatile) that \tt T has, or the code will fail to + compile. Use qSharedPointerConstCast to cast away the constness. + + \sa QWeakPointer::toStrongRef(), qSharedPointerCast(), qSharedPointerConstCast() +*/ + + +/*! \fn QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &other) \relates QWeakPointer |