diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2014-06-30 09:56:26 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@digia.com> | 2014-07-03 10:57:40 +0200 |
commit | b398515b09d23b5b94d16676b709de6c0b382e56 (patch) | |
tree | 21f9aef9e1eafa1bd62027f721978926b31b3af3 /src | |
parent | 7021188778c6eb80a721c8975b68cf6b44444839 (diff) |
Tidy up and expand QSharedPointer documentation.
Also adds the 5.4.0 changes file.
Change-Id: I10967ca179b91229e7d1ee0fc666bbd8dbe54425
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 180f45eb56..e0cd54022e 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -374,12 +374,12 @@ /*! \class QEnableSharedFromThis \inmodule QtCore - \brief A base class that allows to obtain a QSharedPointer for an object already managed by a shared pointer + \brief A base class that allows obtaining a QSharedPointer for an object already managed by a shared pointer \since 5.4 You can inherit this class when you need to create a QSharedPointer - from any instance of a class -- for instance, from within the - object itself. The key point is that the "obvious" technique of + from any instance of a class; for instance, from within the + object itself. The key point is that the technique of just returning QSharedPointer<T>(this) can not be used, because this winds up creating multiple distinct QSharedPointer objects with separate reference counts. For this reason you must never @@ -406,6 +406,27 @@ Q_ASSERT(p == y); // p and q must share ownership } \endcode + + It is also possible to get a shared pointer from an object outside of + the class itself. This is especially useful in code that provides an + interface to scripts, where it is currently not possible to use shared + pointers. For example: + + \code + class ScriptInterface : public QObject + { + Q_OBJECT + + // ... + + public slots: + void slotCalledByScript(Y *managedBySharedPointer) + { + QSharedPointer<Y> yPtr = managedBySharedPointer->sharedFromThis(); + // Some other code unrelated to scripts that expects a QSharedPointer<Y> ... + } + }; + \endcode */ /*! |