Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 864

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qsharedpointer.cpp -->
  <title>QWeakPointer Class | Qt Core 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QWeakPointer</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#related-non-members">Related Non-Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QWeakPointer Class</h1>
<!-- $$$QWeakPointer-brief -->
<p>The <a href="qweakpointer.html">QWeakPointer</a> class holds a weak reference to a shared pointer <a href="#details">More...</a></p>
<!-- @@@QWeakPointer -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QWeakPointer&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 4.5</td></tr></table></div><ul>
<li><a href="qweakpointer-members.html">List of all members, including inherited members</a></li>
<li><a href="qweakpointer-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#QWeakPointer-1">QWeakPointer</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#QWeakPointer-2">QWeakPointer</a></b>(const QSharedPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#dtor.QWeakPointer">~QWeakPointer</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#clear">clear</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T *</td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#data">data</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#isNull">isNull</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;T&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#lock">lock</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#swap">swap</a></b>(QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;T&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#toStrongRef">toStrongRef</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-bool">operator bool</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-not">operator!</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QWeakPointer&lt;T&gt; &amp;</td><td class="memItemRight bottomAlign"><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 rightAlign topAlign"> QWeakPointer&lt;T&gt; &amp;</td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-1">operator=</a></b>(const QSharedPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
</table></div>
<a name="related-non-members"></a>
<h2 id="related-non-members">Related Non-Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#qSharedPointerCast">qSharedPointerCast</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#qSharedPointerDynamicCast">qSharedPointerDynamicCast</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#qSharedPointerObjectCast">qSharedPointerObjectCast</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QWeakPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#qWeakPointerCast">qWeakPointerCast</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-not-eq">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 rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-not-eq-1">operator!=</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>lhs</i>, <i>std::nullptr_t</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-not-eq-2">operator!=</a></b>(<i>std::nullptr_t</i>, const QWeakPointer&lt;T&gt; &amp;<i>rhs</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-not-eq-3">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 rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-eq">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 rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-eq-1">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 rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-eq-2">operator==</a></b>(const QWeakPointer&lt;T&gt; &amp;<i>lhs</i>, <i>std::nullptr_t</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-eq-3">operator==</a></b>(<i>std::nullptr_t</i>, const QWeakPointer&lt;T&gt; &amp;<i>rhs</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QWeakPointer-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qweakpointer.html">QWeakPointer</a> class holds a weak reference to a shared pointer</p>
<p>The <a href="qweakpointer.html">QWeakPointer</a> 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><a href="qweakpointer.html">QWeakPointer</a> objects can only be created by assignment from a <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>It's important to note that <a href="qweakpointer.html">QWeakPointer</a> provides no automatic casting operators to prevent mistakes from happening. Even though <a href="qweakpointer.html">QWeakPointer</a> 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 <a href="qweakpointer.html">QWeakPointer</a> 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 an example.</p>
<p><a href="qweakpointer.html">QWeakPointer</a> 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>
</div>
<p><b>See also </b><a href="qsharedpointer.html">QSharedPointer</a> and <a href="qscopedpointer.html">QScopedPointer</a>.</p>
<!-- @@@QWeakPointer -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QWeakPointer[overload1]$$$QWeakPointer -->
<h3 class="fn" id="QWeakPointer"><a name="QWeakPointer"></a>QWeakPointer::<span class="name">QWeakPointer</span>()</h3>
<p>Creates a <a href="qweakpointer.html">QWeakPointer</a> that points to nothing.</p>
<!-- @@@QWeakPointer -->
<!-- $$$QWeakPointer$$$QWeakPointerconstQWeakPointer<T>& -->
<h3 class="fn" id="QWeakPointer-1"><a name="QWeakPointer-1"></a>QWeakPointer::<span class="name">QWeakPointer</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&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 <code>T</code> 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>
<!-- @@@QWeakPointer -->
<!-- $$$QWeakPointer$$$QWeakPointerconstQSharedPointer<T>& -->
<h3 class="fn" id="QWeakPointer-2"><a name="QWeakPointer-2"></a>QWeakPointer::<span class="name">QWeakPointer</span>(const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&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 <code>T</code> 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>
<!-- @@@QWeakPointer -->
<!-- $$$~QWeakPointer[overload1]$$$~QWeakPointer -->
<h3 class="fn" id="dtor.QWeakPointer"><a name="dtor.QWeakPointer"></a>QWeakPointer::<span class="name">~QWeakPointer</span>()</h3>
<p>Destroys this <a href="qweakpointer.html">QWeakPointer</a> object. The pointer referenced by this object will not be deleted.</p>
<!-- @@@~QWeakPointer -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn" id="clear"><a name="clear"></a><span class="type">void</span> QWeakPointer::<span class="name">clear</span>()</h3>
<p>Clears this <a href="qweakpointer.html">QWeakPointer</a> object, dropping the reference that it may have had to the pointer.</p>
<!-- @@@clear -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn" id="data"><a name="data"></a><span class="type">T</span> *QWeakPointer::<span class="name">data</span>() const</h3>
<p>Returns the value of the pointer being tracked by this <a href="qweakpointer.html">QWeakPointer</a>, <b>without</b> 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 class="cpp">

  <a href="qtglobal.html#qDebug">qDebug</a>(<span class="string">&quot;Tracking %p&quot;</span><span class="operator">,</span> weakref<span class="operator">.</span>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 class="cpp">

  <span class="comment">// this pointer cannot be used in another thread</span>
  <span class="comment">// so other threads cannot delete it</span>
  <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span> weakref <span class="operator">=</span> obtainReference();

  Object <span class="operator">*</span>obj <span class="operator">=</span> weakref<span class="operator">.</span>data();
  <span class="keyword">if</span> (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><b>See also </b><a href="qweakpointer.html#isNull">isNull</a>() and <a href="qweakpointer.html#toStrongRef">toStrongRef</a>().</p>
<!-- @@@data -->
<!-- $$$isNull[overload1]$$$isNull -->
<h3 class="fn" id="isNull"><a name="isNull"></a><span class="type">bool</span> QWeakPointer::<span class="name">isNull</span>() const</h3>
<p>Returns <code>true</code> 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>
<!-- @@@isNull -->
<!-- $$$lock[overload1]$$$lock -->
<h3 class="fn" id="lock"><a name="lock"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&gt; QWeakPointer::<span class="name">lock</span>() const</h3>
<p>Same as <a href="qweakpointer.html#toStrongRef">toStrongRef</a>().</p>
<p>This function is provided for API compatibility with std::weak_ptr.</p>
<p>This function was introduced in  Qt 5.4.</p>
<!-- @@@lock -->
<!-- $$$swap[overload1]$$$swapQWeakPointer<T>& -->
<h3 class="fn" id="swap"><a name="swap"></a><span class="type">void</span> QWeakPointer::<span class="name">swap</span>(<span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>)</h3>
<p>Swaps this weak pointer instance with <i>other</i>. This function is very fast and never fails.</p>
<p>This function was introduced in  Qt 5.4.</p>
<!-- @@@swap -->
<!-- $$$toStrongRef[overload1]$$$toStrongRef -->
<h3 class="fn" id="toStrongRef"><a name="toStrongRef"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&gt; QWeakPointer::<span class="name">toStrongRef</span>() 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 class="cpp">

  <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span> weakref;

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

  <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span> strong <span class="operator">=</span> weakref<span class="operator">.</span>toStrongRef();
  <span class="keyword">if</span> (strong)
      <a href="qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The value is:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="operator">*</span>strong;
  <span class="keyword">else</span>
      <a href="qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The value has already been deleted&quot;</span>;

</pre>
<p><b>See also </b><a href="qsharedpointer.html#QSharedPointer">QSharedPointer::QSharedPointer</a>().</p>
<!-- @@@toStrongRef -->
<!-- $$$operator bool[overload1]$$$operator bool -->
<h3 class="fn" id="operator-bool"><a name="operator-bool"></a>QWeakPointer::<span class="name">operator bool</span>() const</h3>
<p>Returns <code>true</code> if this object is not null. This function is suitable for use in <code>if-constructs</code>, like:</p>
<pre class="cpp">

  <span class="keyword">if</span> (weakref) { <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> }

</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><b>See also </b><a href="qweakpointer.html#isNull">isNull</a>().</p>
<!-- @@@operator bool -->
<!-- $$$operator![overload1]$$$operator! -->
<h3 class="fn" id="operator-not"><a name="operator-not"></a><span class="type">bool</span> QWeakPointer::<span class="name">operator!</span>() const</h3>
<p>Returns <code>true</code> if this object is null. This function is suitable for use in <code>if-constructs</code>, like:</p>
<pre class="cpp">

  <span class="keyword">if</span> (<span class="operator">!</span>weakref) { <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> }

</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><b>See also </b><a href="qweakpointer.html#isNull">isNull</a>().</p>
<!-- @@@operator! -->
<!-- $$$operator=[overload1]$$$operator=constQWeakPointer<T>& -->
<h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;QWeakPointer::<span class="name">operator=</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&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 <code>T</code> 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>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=constQSharedPointer<T>& -->
<h3 class="fn" id="operator-eq-1"><a name="operator-eq-1"></a><span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;QWeakPointer::<span class="name">operator=</span>(const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&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 <code>T</code> 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>
<!-- @@@operator= -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$qSharedPointerCast[overload1]$$$qSharedPointerCastconstQWeakPointer<T>& -->
<h3 class="fn" id="qSharedPointerCast"><a name="qSharedPointerCast"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; <span class="name">qSharedPointerCast</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>)</h3>
<p>Returns a shared pointer to the pointer held by <i>other</i>, cast to type <code>X</code>. The types <code>T</code> and <code>X</code> must belong to one hierarchy for the <code>static_cast</code> 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 <code>X</code> must have the same cv-qualifiers (<code>const</code> and <code>volatile</code>) that <code>T</code> has, or the code will fail to compile. Use <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a> to cast away the constness.</p>
<p><b>See also </b><a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerDynamicCast">qSharedPointerDynamicCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<!-- @@@qSharedPointerCast -->
<!-- $$$qSharedPointerConstCast[overload1]$$$qSharedPointerConstCastconstQWeakPointer<T>& -->
<h3 class="fn" id="qSharedPointerConstCast"><a name="qSharedPointerConstCast"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; <span class="name">qSharedPointerConstCast</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>)</h3>
<p>Returns a shared pointer to the pointer held by <i>other</i>, cast to type <code>X</code>. The types <code>T</code> and <code>X</code> must belong to one hierarchy for the <code>const_cast</code> to succeed. The <code>const</code> and <code>volatile</code> differences between <code>T</code> and <code>X</code> 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><b>See also </b><a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerDynamicCast">qSharedPointerDynamicCast</a>().</p>
<!-- @@@qSharedPointerConstCast -->
<!-- $$$qSharedPointerDynamicCast[overload1]$$$qSharedPointerDynamicCastconstQWeakPointer<T>& -->
<h3 class="fn" id="qSharedPointerDynamicCast"><a name="qSharedPointerDynamicCast"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; <span class="name">qSharedPointerDynamicCast</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&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 <code>X</code> to obtain an internal pointer of the appropriate type. If the <code>dynamic_cast</code> 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 <code>X</code> must have the same cv-qualifiers (<code>const</code> and <code>volatile</code>) that <code>T</code> has, or the code will fail to compile. Use <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a> to cast away the constness.</p>
<p><b>See also </b><a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<!-- @@@qSharedPointerDynamicCast -->
<!-- $$$qSharedPointerObjectCast[overload1]$$$qSharedPointerObjectCastconstQWeakPointer<T>& -->
<h3 class="fn" id="qSharedPointerObjectCast"><a name="qSharedPointerObjectCast"></a><span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; <span class="name">qSharedPointerObjectCast</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>)</h3>
<p>The <a href="qsharedpointer.html#qSharedPointerObjectCast">qSharedPointerObjectCast</a> 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 <code>X</code> to obtain an internal pointer of the appropriate type. If the <code>qobject_cast</code> 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 <code>X</code> must have the same cv-qualifiers (<code>const</code> and <code>volatile</code>) that <code>T</code> has, or the code will fail to compile. Use <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a> to cast away the constness.</p>
<p>This function was introduced in  Qt 4.6.</p>
<p><b>See also </b><a href="qweakpointer.html#toStrongRef">QWeakPointer::toStrongRef</a>(), <a href="qsharedpointer.html#qSharedPointerCast">qSharedPointerCast</a>(), and <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a>().</p>
<!-- @@@qSharedPointerObjectCast -->
<!-- $$$qWeakPointerCast[overload1]$$$qWeakPointerCastconstQWeakPointer<T>& -->
<h3 class="fn" id="qWeakPointerCast"><a name="qWeakPointerCast"></a><span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">X</span>&gt; <span class="name">qWeakPointerCast</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>)</h3>
<p>Returns a weak pointer to the pointer held by <i>other</i>, cast to type <code>X</code>. The types <code>T</code> and <code>X</code> must belong to one hierarchy for the <code>static_cast</code> to succeed.</p>
<p>Note that <code>X</code> must have the same cv-qualifiers (<code>const</code> and <code>volatile</code>) that <code>T</code> has, or the code will fail to compile. Use <a href="qsharedpointer.html#qSharedPointerConstCast">qSharedPointerConstCast</a> to cast away the constness.</p>
<!-- @@@qWeakPointerCast -->
<!-- $$$operator!=[overload1]$$$operator!=constQSharedPointer<T>&constQWeakPointer<X>& -->
<h3 class="fn" id="operator-not-eq"><a name="operator-not-eq"></a><span class="type">bool</span> <span class="name">operator!=</span>(const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>ptr1</i>, const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">X</span>&gt; &amp;<i>ptr2</i>)</h3>
<p>Returns <code>true</code> 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 <code>static_cast</code> 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>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQWeakPointer<T>&std::nullptr_t -->
<h3 class="fn" id="operator-not-eq-1"><a name="operator-not-eq-1"></a><span class="type">bool</span> <span class="name">operator!=</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>lhs</i>, <i>std::nullptr_t</i>)</h3>
<p>Returns <code>true</code> if the pointer referenced by <i>lhs</i> is a valid (i.e&#x2e; non-null) pointer.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qweakpointer.html#isNull">QWeakPointer::isNull</a>().</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=std::nullptr_tconstQWeakPointer<T>& -->
<h3 class="fn" id="operator-not-eq-2"><a name="operator-not-eq-2"></a><span class="type">bool</span> <span class="name">operator!=</span>(<i>std::nullptr_t</i>, const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>rhs</i>)</h3>
<p>Returns <code>true</code> if the pointer referenced by <i>rhs</i> is a valid (i.e&#x2e; non-null) pointer.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qweakpointer.html#isNull">QWeakPointer::isNull</a>().</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQWeakPointer<T>&constQSharedPointer<X>& -->
<h3 class="fn" id="operator-not-eq-3"><a name="operator-not-eq-3"></a><span class="type">bool</span> <span class="name">operator!=</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>ptr1</i>, const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; &amp;<i>ptr2</i>)</h3>
<p>Returns <code>true</code> 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 <code>static_cast</code> 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>
<!-- @@@operator!= -->
<!-- $$$operator==[overload1]$$$operator==constQSharedPointer<T>&constQWeakPointer<X>& -->
<h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> <span class="name">operator==</span>(const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>ptr1</i>, const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">X</span>&gt; &amp;<i>ptr2</i>)</h3>
<p>Returns <code>true</code> 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 <code>static_cast</code> 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>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQWeakPointer<T>&constQSharedPointer<X>& -->
<h3 class="fn" id="operator-eq-eq-1"><a name="operator-eq-eq-1"></a><span class="type">bool</span> <span class="name">operator==</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>ptr1</i>, const <span class="type"><a href="qsharedpointer.html">QSharedPointer</a></span>&lt;<span class="type">X</span>&gt; &amp;<i>ptr2</i>)</h3>
<p>Returns <code>true</code> 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 <code>static_cast</code> 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>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQWeakPointer<T>&std::nullptr_t -->
<h3 class="fn" id="operator-eq-eq-2"><a name="operator-eq-eq-2"></a><span class="type">bool</span> <span class="name">operator==</span>(const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>lhs</i>, <i>std::nullptr_t</i>)</h3>
<p>Returns <code>true</code> if the pointer referenced by <i>lhs</i> is a null pointer.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qweakpointer.html#isNull">QWeakPointer::isNull</a>().</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==std::nullptr_tconstQWeakPointer<T>& -->
<h3 class="fn" id="operator-eq-eq-3"><a name="operator-eq-eq-3"></a><span class="type">bool</span> <span class="name">operator==</span>(<i>std::nullptr_t</i>, const <span class="type"><a href="qweakpointer.html#QWeakPointer">QWeakPointer</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>rhs</i>)</h3>
<p>Returns <code>true</code> if the pointer referenced by <i>rhs</i> is a null pointer.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qweakpointer.html#isNull">QWeakPointer::isNull</a>().</p>
<!-- @@@operator== -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>