Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 5450

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qsharedpointer.cpp -->
<head>
  <title>Qt 4.6: QWeakPointer Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a name="//apple_ref/cpp/cl//QWeakPointer"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QWeakPointer Class Reference<br /><span class="small-subtitle">[<a href="qtcore.html">QtCore</a> module]</span>
</h1>
<p>The QWeakPointer class holds a weak reference to a shared pointer <a href="#details">More...</a></p>
<pre> #include &lt;QWeakPointer&gt;</pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<p>This class was introduced in Qt 4.5.</p>
<ul>
<li><a href="qweakpointer-members.html">List of all members, including inherited members</a></li>
</ul>
<hr />
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#QWeakPointer-2">QWeakPointer</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#QWeakPointer-3">QWeakPointer</a></b> ( const QSharedPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#QWeakPointer-4">QWeakPointer</a></b> ( const QObject * <i>obj</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#dtor.QWeakPointer">~QWeakPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#clear">clear</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#data">data</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#isNull">isNull</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QSharedPointer&lt;T&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#toStrongRef">toStrongRef</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-bool">operator bool</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-not">operator!</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QWeakPointer&lt;T&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-eq">operator=</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QWeakPointer&lt;T&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-eq-2">operator=</a></b> ( const QSharedPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QWeakPointer&lt;T&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-eq-3">operator=</a></b> ( const QObject * <i>obj</i> )</td></tr>
</table>
<hr />
<a name="related-non-members"></a>
<h2>Related Non-Members</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">QSharedPointer&lt;X&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#qSharedPointerCast-2">qSharedPointerCast</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QSharedPointer&lt;X&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#qSharedPointerConstCast-2">qSharedPointerConstCast</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QSharedPointer&lt;X&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#qSharedPointerDynamicCast-2">qSharedPointerDynamicCast</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QSharedPointer&lt;X&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#qSharedPointerObjectCast-2">qSharedPointerObjectCast</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QWeakPointer&lt;X&gt; </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#qWeakPointerCast">qWeakPointerCast</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-not-eq-22">operator!=</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>ptr1</i>, const QSharedPointer&lt;X&gt; &amp; <i>ptr2</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-not-eq-23">operator!=</a></b> ( const QSharedPointer&lt;T&gt; &amp; <i>ptr1</i>, const QWeakPointer&lt;X&gt; &amp; <i>ptr2</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-eq-eq-41">operator==</a></b> ( const QWeakPointer&lt;T&gt; &amp; <i>ptr1</i>, const QSharedPointer&lt;X&gt; &amp; <i>ptr2</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qweakpointer.html#operator-eq-eq-42">operator==</a></b> ( const QSharedPointer&lt;T&gt; &amp; <i>ptr1</i>, const QWeakPointer&lt;X&gt; &amp; <i>ptr2</i> )</td></tr>
</table>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QWeakPointer class holds a weak reference to a shared pointer</p>
<p>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.</p>
<p>QWeakPointer objects can only be created by assignment from a <a href="qsharedpointer.html">QSharedPointer</a>. The exception is pointers derived from <a href="qobject.html">QObject</a>: in that case, QWeakPointer serves as a replacement to <a href="qpointer.html">QPointer</a>.</p>
<p>It's important to note that QWeakPointer provides no automatic casting operators to prevent mistakes from happening. Even though QWeakPointer tracks a pointer, it should not be considered a pointer itself, since it doesn't guarantee that the pointed object remains valid.</p>
<p>Therefore, to access the pointer that QWeakPointer is tracking, you must first promote it to <a href="qsharedpointer.html">QSharedPointer</a> and verify if the resulting object is null or not. <a href="qsharedpointer.html">QSharedPointer</a> guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. See <a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>() for more an example.</p>
<p>QWeakPointer also provides the <a href="qweakpointer.html#data">QWeakPointer::data</a>() method that returns the tracked pointer without ensuring that it remains valid. This function is provided if you can guarantee by external means that the object will not get deleted (or if you only need the pointer value) and the cost of creating a <a href="qsharedpointer.html">QSharedPointer</a> using <a href="qweakpointer.html#toStrongRef">toStrongRef</a>() is too high.</p>
<p>That function can also be used to obtain the tracked pointer for QWeakPointers that cannot be promoted to <a href="qsharedpointer.html">QSharedPointer</a>, such as those created directly from a <a href="qobject.html">QObject</a> pointer (not via <a href="qsharedpointer.html">QSharedPointer</a>).</p>
<a name="tracking-qobject"></a>
<h3>Tracking QObject</h3>
<p>QWeakPointer can be used to track deletion classes derives from <a href="qobject.html">QObject</a>, even if they are not managed by <a href="qsharedpointer.html">QSharedPointer</a>. When used in that role, QWeakPointer replaces the older <a href="qpointer.html">QPointer</a> in all use-cases. QWeakPointer is also more efficient than <a href="qpointer.html">QPointer</a>, so it should be preferred in all new code.</p>
<p>To do that, QWeakPointer provides a special constructor that is only available if the template parameter <tt>T</tt> is either <a href="qobject.html">QObject</a> or a class deriving from it. Trying to use that constructor if <tt>T</tt> does not derive from <a href="qobject.html">QObject</a> will result in compilation errors.</p>
<p>To obtain the <a href="qobject.html">QObject</a> being tracked by QWeakPointer, you must use the <a href="qweakpointer.html#data">QWeakPointer::data</a>() function, but only if you can guarantee that the object cannot get deleted by another context. It should be noted that <a href="qpointer.html">QPointer</a> had the same constraint, so use of QWeakPointer forces you to consider whether the pointer is still valid.</p>
<p><a href="qobject.html">QObject</a>-derived classes can only be deleted in the thread they have affinity to (which is the thread they were created in or moved to, using <a href="qobject.html#moveToThread">QObject::moveToThread</a>()). In special, <a href="qwidget.html">QWidget</a>-derived classes cannot be created in non-GUI threads nor moved there. Therefore, guaranteeing that the tracked <a href="qobject.html">QObject</a> has affinity to the current thread is enough to also guarantee that it won't be deleted asynchronously.</p>
<p>Note that QWeakPointer's size and data layout do not match <a href="qpointer.html">QPointer</a>, so it cannot replace that class in a binary-compatible manner.</p>
<p>Care must also be taken with QWeakPointers created directly from <a href="qobject.html">QObject</a> pointers when dealing with code that was compiled with Qt versions prior to 4.6&#x2e; Those versions may not track the reference counters correctly, so QWeakPointers created from <a href="qobject.html">QObject</a> should never be passed to code that hasn't been recompiled.</p>
<p>See also <a href="qsharedpointer.html">QSharedPointer</a> and <a href="qscopedpointer.html">QScopedPointer</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<a name="//apple_ref/cpp/instm/QWeakPointer/QWeakPointer"></a>
<h3 class="fn"><a name="QWeakPointer"></a>QWeakPointer::QWeakPointer ()</h3>
<p>Creates a <a href="qweakpointer.html">QWeakPointer</a> that points to nothing.</p>
<h3 class="fn"><a name="QWeakPointer-2"></a>QWeakPointer::QWeakPointer ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Creates a <a href="qweakpointer.html">QWeakPointer</a> that holds a weak reference to the pointer referenced by <i>other</i>.</p>
<p>If <tt>T</tt> is a derived type of the template parameter of this class, <a href="qweakpointer.html">QWeakPointer</a> will perform an automatic cast. Otherwise, you will get a compiler error.</p>
<h3 class="fn"><a name="QWeakPointer-3"></a>QWeakPointer::QWeakPointer ( const <a href="qsharedpointer.html">QSharedPointer</a>&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Creates a <a href="qweakpointer.html">QWeakPointer</a> that holds a weak reference to the pointer referenced by <i>other</i>.</p>
<p>If <tt>T</tt> is a derived type of the template parameter of this class, <a href="qweakpointer.html">QWeakPointer</a> will perform an automatic cast. Otherwise, you will get a compiler error.</p>
<h3 class="fn"><a name="QWeakPointer-4"></a>QWeakPointer::QWeakPointer ( const <a href="qobject.html">QObject</a> * <i>obj</i> )</h3>
<p>Creates a <a href="qweakpointer.html">QWeakPointer</a> that holds a weak reference directly to the <a href="qobject.html">QObject</a> <i>obj</i>. This constructor is only available if the template type <tt>T</tt> is <a href="qobject.html">QObject</a> or derives from it (otherwise a compilation error will result).</p>
<p>You can use this constructor with any <a href="qobject.html">QObject</a>, even if they were not created with <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>Note that QWeakPointers created this way on arbitrary QObjects usually cannot be promoted to <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qsharedpointer.html">QSharedPointer</a> and <a href="qweakpointer.html#tracking-qobject">QWeakPointer#tracking-qobject</a>.</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/~QWeakPointer"></a>
<h3 class="fn"><a name="dtor.QWeakPointer"></a>QWeakPointer::~QWeakPointer ()</h3>
<p>Destroys this <a href="qweakpointer.html">QWeakPointer</a> object. The pointer referenced by this object will not be deleted.</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/clear"></a>
<h3 class="fn"><a name="clear"></a>void QWeakPointer::clear ()</h3>
<p>Clears this <a href="qweakpointer.html">QWeakPointer</a> object, dropping the reference that it may have had to the pointer.</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/data"></a>
<h3 class="fn"><a name="data"></a>T * QWeakPointer::data () const</h3>
<p>Returns the value of the pointer being tracked by this <a href="qweakpointer.html">QWeakPointer</a>, \b without ensuring that it cannot get deleted. To have that guarantee, use <a href="qweakpointer.html#toStrongRef">toStrongRef</a>(), which returns a <a href="qsharedpointer.html">QSharedPointer</a> object. If this function can determine that the pointer has already been deleted, it returns 0.</p>
<p>It is ok to obtain the value of the pointer and using that value itself, like for example in debugging statements:</p>
<pre> qDebug(&quot;Tracking %p&quot;, weakref.data());</pre>
<p>However, dereferencing the pointer is only allowed if you can guarantee by external means that the pointer does not get deleted. For example, if you can be certain that no other thread can delete it, nor the functions that you may call.</p>
<p>If that is the case, then the following code is valid:</p>
<pre><span class="comment"> // this pointer cannot be used in another thread</span>
<span class="comment"> // so other threads cannot delete it</span>
 QWeakPointer&lt;int&gt; weakref = obtainReference();

 Object *obj = weakref.data();
 if (obj) {
     <span class="comment">// if the pointer wasn't deleted yet, we know it can't get</span>
     <span class="comment">// deleted by our own code here nor the functions we call</span>
     otherFunction(obj);
 }</pre>
<p>Use this function with care.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qweakpointer.html#isNull">isNull</a>() and <a href="qweakpointer.html#toStrongRef">toStrongRef</a>().</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/isNull"></a>
<h3 class="fn"><a name="isNull"></a>bool QWeakPointer::isNull () const</h3>
<p>Returns true if this object is holding a reference to a null pointer.</p>
<p>Note that, due to the nature of weak references, the pointer that <a href="qweakpointer.html">QWeakPointer</a> 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.</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/toStrongRef"></a>
<h3 class="fn"><a name="toStrongRef"></a><a href="qsharedpointer.html">QSharedPointer</a>&lt;T&gt; QWeakPointer::toStrongRef () const</h3>
<p>Promotes this weak reference to a strong one and returns a <a href="qsharedpointer.html">QSharedPointer</a> object holding that reference. When promoting to <a href="qsharedpointer.html">QSharedPointer</a>, this function verifies if the object has been deleted already or not. If it hasn't, this function increases the reference count to the shared object, thus ensuring that it will not get deleted.</p>
<p>Since this function can fail to obtain a valid strong reference to the shared object, you should always verify if the conversion succeeded, by calling <a href="qsharedpointer.html#isNull">QSharedPointer::isNull</a>() on the returned object.</p>
<p>For example, the following code promotes a <a href="qweakpointer.html">QWeakPointer</a> that was held to a strong reference and, if it succeeded, it prints the value of the integer that was held:</p>
<pre> QWeakPointer&lt;int&gt; weakref;

<span class="comment"> // ...</span>

 QSharedPointer&lt;int&gt; strong = weakref.toStrongRef();
 if (strong)
     qDebug() &lt;&lt; &quot;The value is:&quot; &lt;&lt; *strong;
 else
     qDebug() &lt;&lt; &quot;The value has already been deleted&quot;;</pre>
<p>See also <a href="qsharedpointer.html#QSharedPointer">QSharedPointer::QSharedPointer</a>().</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/operator bool"></a>
<h3 class="fn"><a name="operator-bool"></a>QWeakPointer::operator bool () const</h3>
<p>Returns true if this object is not null. This function is suitable for use in <tt>if-constructs</tt>, like:</p>
<pre> if (weakref) { ... }</pre>
<p>Note that, due to the nature of weak references, the pointer that <a href="qweakpointer.html">QWeakPointer</a> 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.</p>
<p>See also <a href="qweakpointer.html#isNull">isNull</a>().</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/operator!"></a>
<h3 class="fn"><a name="operator-not"></a>bool QWeakPointer::operator! () const</h3>
<p>Returns true if this object is null. This function is suitable for use in <tt>if-constructs</tt>, like:</p>
<pre> if (!weakref) { ... }</pre>
<p>Note that, due to the nature of weak references, the pointer that <a href="qweakpointer.html">QWeakPointer</a> 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.</p>
<p>See also <a href="qweakpointer.html#isNull">isNull</a>().</p>
<a name="//apple_ref/cpp/instm/QWeakPointer/operator="></a>
<h3 class="fn"><a name="operator-eq"></a>QWeakPointer&lt;T&gt; QWeakPointer::operator= ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Makes this object share <i>other</i>'s pointer. The current pointer reference is discarded but is not deleted.</p>
<p>If <tt>T</tt> is a derived type of the template parameter of this class, <a href="qweakpointer.html">QWeakPointer</a> will perform an automatic cast. Otherwise, you will get a compiler error.</p>
<h3 class="fn"><a name="operator-eq-2"></a>QWeakPointer&lt;T&gt; QWeakPointer::operator= ( const <a href="qsharedpointer.html">QSharedPointer</a>&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Makes this object share <i>other</i>'s pointer. The current pointer reference is discarded but is not deleted.</p>
<p>If <tt>T</tt> is a derived type of the template parameter of this class, <a href="qweakpointer.html">QWeakPointer</a> will perform an automatic cast. Otherwise, you will get a compiler error.</p>
<h3 class="fn"><a name="operator-eq-3"></a>QWeakPointer&lt;T&gt; QWeakPointer::operator= ( const <a href="qobject.html">QObject</a> * <i>obj</i> )</h3>
<p>Makes this <a href="qweakpointer.html">QWeakPointer</a> hold a weak reference to directly to the <a href="qobject.html">QObject</a> <i>obj</i>. This function is only available if the template type <tt>T</tt> is <a href="qobject.html">QObject</a> or derives from it.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qweakpointer.html#tracking-qobject">QWeakPointer#tracking-qobject</a>.</p>
<hr />
<h2>Related Non-Members</h2>
<h3 class="fn"><a name="qSharedPointerCast-2"></a><a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; qSharedPointerCast ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Returns a shared pointer to the pointer held by <i>other</i>, cast to type <tt>X</tt>. The types <tt>T</tt> and <tt>X</tt> must belong to one hierarchy for the <tt>static_cast</tt> to succeed.</p>
<p>The <i>other</i> 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 <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>Note that <tt>X</tt> must have the same cv-qualifiers (<tt>const</tt> and <tt>volatile</tt>) that <tt>T</tt> has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.</p>
<p>See also <a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerDynamicCast">qSharedPointerDynamicCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<h3 class="fn"><a name="qSharedPointerConstCast-2"></a><a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; qSharedPointerConstCast ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Returns a shared pointer to the pointer held by <i>other</i>, cast to type <tt>X</tt>. The types <tt>T</tt> and <tt>X</tt> must belong to one hierarchy for the <tt>const_cast</tt> to succeed. The <tt>const</tt> and <tt>volatile</tt> differences between <tt>T</tt> and <tt>X</tt> are ignored.</p>
<p>The <i>other</i> 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 <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>See also <a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerDynamicCast">qSharedPointerDynamicCast</a>().</p>
<h3 class="fn"><a name="qSharedPointerDynamicCast-2"></a><a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; qSharedPointerDynamicCast ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Returns a shared pointer to the pointer held by <i>other</i>, using a dynamic cast to type <tt>X</tt> to obtain an internal pointer of the appropriate type. If the <tt>dynamic_cast</tt> fails, the object returned will be null.</p>
<p>The <i>other</i> 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 <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>Note that <tt>X</tt> must have the same cv-qualifiers (<tt>const</tt> and <tt>volatile</tt>) that <tt>T</tt> has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.</p>
<p>See also <a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<h3 class="fn"><a name="qSharedPointerObjectCast-2"></a><a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; qSharedPointerObjectCast ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>The qSharedPointerObjectCast function is for casting a shared pointer.</p>
<p>Returns a shared pointer to the pointer held by <i>other</i>, using a <a href="qobject.html#qobject_cast">qobject_cast</a>() to type <tt>X</tt> to obtain an internal pointer of the appropriate type. If the <tt>qobject_cast</tt> fails, the object returned will be null.</p>
<p>The <i>other</i> 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 <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>Note that <tt>X</tt> must have the same cv-qualifiers (<tt>const</tt> and <tt>volatile</tt>) that <tt>T</tt> has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<a name="//apple_ref/cpp/func//qWeakPointerCast"></a>
<h3 class="fn"><a name="qWeakPointerCast"></a>QWeakPointer&lt;X&gt; qWeakPointerCast ( const QWeakPointer&lt;T&gt; &amp; <i>other</i> )</h3>
<p>Returns a weak pointer to the pointer held by <i>other</i>, cast to type <tt>X</tt>. The types <tt>T</tt> and <tt>X</tt> must belong to one hierarchy for the <tt>static_cast</tt> to succeed.</p>
<p>Note that <tt>X</tt> must have the same cv-qualifiers (<tt>const</tt> and <tt>volatile</tt>) that <tt>T</tt> has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.</p>
<h3 class="fn"><a name="operator-not-eq-22"></a>bool operator!= ( const QWeakPointer&lt;T&gt; &amp; <i>ptr1</i>, const <a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; &amp; <i>ptr2</i> )</h3>
<p>Returns true if the pointer referenced by <i>ptr1</i> is not the same pointer as that referenced by <i>ptr2</i>.</p>
<p>If <i>ptr2</i>'s template parameter is different from <i>ptr1</i>'s, <a href="qsharedpointer.html">QSharedPointer</a> will attempt to perform an automatic <tt>static_cast</tt> to ensure that the pointers being compared are equal. If <i>ptr2</i>'s template parameter is not a base or a derived type from <i>ptr1</i>'s, you will get a compiler error.</p>
<h3 class="fn"><a name="operator-not-eq-23"></a>bool operator!= ( const <a href="qsharedpointer.html">QSharedPointer</a>&lt;T&gt; &amp; <i>ptr1</i>, const QWeakPointer&lt;X&gt; &amp; <i>ptr2</i> )</h3>
<p>Returns true if the pointer referenced by <i>ptr1</i> is not the same pointer as that referenced by <i>ptr2</i>.</p>
<p>If <i>ptr2</i>'s template parameter is different from <i>ptr1</i>'s, <a href="qsharedpointer.html">QSharedPointer</a> will attempt to perform an automatic <tt>static_cast</tt> to ensure that the pointers being compared are equal. If <i>ptr2</i>'s template parameter is not a base or a derived type from <i>ptr1</i>'s, you will get a compiler error.</p>
<h3 class="fn"><a name="operator-eq-eq-41"></a>bool operator== ( const QWeakPointer&lt;T&gt; &amp; <i>ptr1</i>, const <a href="qsharedpointer.html">QSharedPointer</a>&lt;X&gt; &amp; <i>ptr2</i> )</h3>
<p>Returns true if the pointer referenced by <i>ptr1</i> is the same pointer as that referenced by <i>ptr2</i>.</p>
<p>If <i>ptr2</i>'s template parameter is different from <i>ptr1</i>'s, <a href="qsharedpointer.html">QSharedPointer</a> will attempt to perform an automatic <tt>static_cast</tt> to ensure that the pointers being compared are equal. If <i>ptr2</i>'s template parameter is not a base or a derived type from <i>ptr1</i>'s, you will get a compiler error.</p>
<h3 class="fn"><a name="operator-eq-eq-42"></a>bool operator== ( const <a href="qsharedpointer.html">QSharedPointer</a>&lt;T&gt; &amp; <i>ptr1</i>, const QWeakPointer&lt;X&gt; &amp; <i>ptr2</i> )</h3>
<p>Returns true if the pointer referenced by <i>ptr1</i> is the same pointer as that referenced by <i>ptr2</i>.</p>
<p>If <i>ptr2</i>'s template parameter is different from <i>ptr1</i>'s, <a href="qsharedpointer.html">QSharedPointer</a> will attempt to perform an automatic <tt>static_cast</tt> to ensure that the pointers being compared are equal. If <i>ptr2</i>'s template parameter is not a base or a derived type from <i>ptr1</i>'s, you will get a compiler error.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>