Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 6997

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qsharedpointer.cpp -->
  <title>Qt 4.8: QWeakPointer Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtcore.html">QtCore</a></li>
<li>QWeakPointer</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<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>
<li class="level2"><a href="#tracking-qobject">Tracking QObject</a></li>
</ul>
</div>
<h1 class="title">QWeakPointer Class Reference</h1>
<!-- $$$QWeakPointer-brief -->
<p>The QWeakPointer class holds a weak reference to a shared pointer <a href="#details">More...</a></p>
<!-- @@@QWeakPointer -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QWeakPointer&gt;</span></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>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<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-2">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-3">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#QWeakPointer-4">QWeakPointer</a></b> ( const QObject * <i>obj</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#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; </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; </td><td class="memItemRight bottomAlign"><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 rightAlign topAlign"> QWeakPointer&lt;T&gt; </td><td class="memItemRight bottomAlign"><b><a href="qweakpointer.html#operator-eq-3">operator=</a></b> ( const QObject * <i>obj</i> )</td></tr>
</table>
<a name="related-non-members"></a>
<h2>Related Non-Members</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><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 rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><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 rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><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 rightAlign topAlign"> QSharedPointer&lt;X&gt; </td><td class="memItemRight bottomAlign"><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 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-28">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-not-eq-29">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-27">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-28">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>
<!-- $$$QWeakPointer-description -->
<div class="descr">
<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 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 of classes that derive 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>
</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"><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"><a name="QWeakPointer-2"></a>QWeakPointer::<span class="name">QWeakPointer</span> ( const <span class="type">QWeakPointer</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 <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>
<!-- @@@QWeakPointer -->
<!-- $$$QWeakPointer$$$QWeakPointerconstQSharedPointer<T>& -->
<h3 class="fn"><a name="QWeakPointer-3"></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 <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>
<!-- @@@QWeakPointer -->
<!-- $$$QWeakPointer$$$QWeakPointerconstQObject* -->
<h3 class="fn"><a name="QWeakPointer-4"></a>QWeakPointer::<span class="name">QWeakPointer</span> ( const <span class="type"><a href="qobject.html">QObject</a></span> * <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 <a href="qtwebkit-bridge.html#qobjects">QObjects</a> usually cannot be promoted to <a href="qsharedpointer.html">QSharedPointer</a>.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also </b><a href="qsharedpointer.html">QSharedPointer</a> and <a href="qweakpointer.html#tracking-qobject">QWeakPointer#tracking-qobject</a>.</p>
<!-- @@@QWeakPointer -->
<!-- $$$~QWeakPointer[overload1]$$$~QWeakPointer -->
<h3 class="fn"><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"><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"><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 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</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"><a name="isNull"></a><span class="type">bool</span> QWeakPointer::<span class="name">isNull</span> () 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>
<!-- @@@isNull -->
<!-- $$$toStrongRef[overload1]$$$toStrongRef -->
<h3 class="fn"><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</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"><a name="operator-bool"></a>QWeakPointer::<span class="name">operator bool</span> () 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 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"><a name="operator-not"></a><span class="type">bool</span> QWeakPointer::<span class="name">operator!</span> () const</h3>
<p>Returns true if this object is null. This function is suitable for use in <tt>if-constructs</tt>, 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"><a name="operator-eq"></a><span class="type">QWeakPointer</span>&lt;<span class="type">T</span>&gt; QWeakPointer::<span class="name">operator=</span> ( const <span class="type">QWeakPointer</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 <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>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=constQSharedPointer<T>& -->
<h3 class="fn"><a name="operator-eq-2"></a><span class="type">QWeakPointer</span>&lt;<span class="type">T</span>&gt; 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 <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>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=constQObject* -->
<h3 class="fn"><a name="operator-eq-3"></a><span class="type">QWeakPointer</span>&lt;<span class="type">T</span>&gt; QWeakPointer::<span class="name">operator=</span> ( const <span class="type"><a href="qobject.html">QObject</a></span> * <i>obj</i> )</h3>
<p>Makes this <a href="qweakpointer.html">QWeakPointer</a> hold a weak reference 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><b>See also </b><a href="qweakpointer.html#tracking-qobject">QWeakPointer#tracking-qobject</a>.</p>
<!-- @@@operator= -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$qSharedPointerCast$$$qSharedPointerCastconstQWeakPointer<T>& -->
<h3 class="fn"><a name="qSharedPointerCast-2"></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">QWeakPointer</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 <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><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$$$qSharedPointerConstCastconstQWeakPointer<T>& -->
<h3 class="fn"><a name="qSharedPointerConstCast-2"></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">QWeakPointer</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 <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><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$$$qSharedPointerDynamicCastconstQWeakPointer<T>& -->
<h3 class="fn"><a name="qSharedPointerDynamicCast-2"></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">QWeakPointer</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 <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><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$$$qSharedPointerObjectCastconstQWeakPointer<T>& -->
<h3 class="fn"><a name="qSharedPointerObjectCast-2"></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">QWeakPointer</span>&lt;<span class="type">T</span>&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><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"><a name="qWeakPointerCast"></a><span class="type">QWeakPointer</span>&lt;<span class="type">X</span>&gt; <span class="name">qWeakPointerCast</span> ( const <span class="type">QWeakPointer</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 <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>
<!-- @@@qWeakPointerCast -->
<!-- $$$operator!=$$$operator!=constQWeakPointer<T>&constQSharedPointer<X>& -->
<h3 class="fn"><a name="operator-not-eq-28"></a><span class="type">bool</span> <span class="name">operator!=</span> ( const <span class="type">QWeakPointer</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 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>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQSharedPointer<T>&constQWeakPointer<X>& -->
<h3 class="fn"><a name="operator-not-eq-29"></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">QWeakPointer</span>&lt;<span class="type">X</span>&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>
<!-- @@@operator!= -->
<!-- $$$operator==$$$operator==constQWeakPointer<T>&constQSharedPointer<X>& -->
<h3 class="fn"><a name="operator-eq-eq-27"></a><span class="type">bool</span> <span class="name">operator==</span> ( const <span class="type">QWeakPointer</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 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>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQSharedPointer<T>&constQWeakPointer<X>& -->
<h3 class="fn"><a name="operator-eq-eq-28"></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">QWeakPointer</span>&lt;<span class="type">X</span>&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>
<!-- @@@operator== -->
</div>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      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.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      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. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>