1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
<?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" />
<!-- qpointer.cpp -->
<title>Qt 4.8: QPointer Class Reference</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<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>QPointer</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>
</ul>
</div>
<h1 class="title">QPointer Class Reference</h1>
<!-- $$$QPointer-brief -->
<p>The QPointer class is a template class that provides guarded pointers to <a href="qobject.html">QObject</a>. <a href="#details">More...</a></p>
<!-- @@@QPointer -->
<pre class="cpp"> <span class="preprocessor">#include <QPointer></span></pre><ul>
<li><a href="qpointer-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="qpointer.html#QPointer">QPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#QPointer-2">QPointer</a></b> ( T * <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#QPointer-3">QPointer</a></b> ( const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#dtor.QPointer">~QPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#data">data</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#isNull">isNull</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-T--2a">operator T *</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-2a">operator*</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator--gt">operator-></a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPointer<T> & </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq">operator=</a></b> ( const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPointer<T> & </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-2">operator=</a></b> ( T * <i>p</i> )</td></tr>
</table>
<a name="related-non-members"></a>
<h2>Related Non-Members</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-not-eq">operator!=</a></b> ( const T * <i>o</i>, const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-not-eq-2">operator!=</a></b> ( const QPointer<T> & <i>p</i>, const T * <i>o</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-not-eq-3">operator!=</a></b> ( T * <i>o</i>, const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-not-eq-4">operator!=</a></b> ( const QPointer<T> & <i>p</i>, T * <i>o</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-not-eq-5">operator!=</a></b> ( const QPointer<T> & <i>p1</i>, const QPointer<T> & <i>p2</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-eq">operator==</a></b> ( const T * <i>o</i>, const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-eq-2">operator==</a></b> ( const QPointer<T> & <i>p</i>, const T * <i>o</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-eq-3">operator==</a></b> ( T * <i>o</i>, const QPointer<T> & <i>p</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-eq-4">operator==</a></b> ( const QPointer<T> & <i>p</i>, T * <i>o</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qpointer.html#operator-eq-eq-5">operator==</a></b> ( const QPointer<T> & <i>p1</i>, const QPointer<T> & <i>p2</i> )</td></tr>
</table>
<a name="details"></a>
<!-- $$$QPointer-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QPointer class is a template class that provides guarded pointers to <a href="qobject.html">QObject</a>.</p>
<p>A guarded pointer, QPointer<T>, behaves like a normal C++ pointer <tt>T *</tt>, except that it is automatically set to 0 when the referenced object is destroyed (unlike normal C++ pointers, which become "dangling pointers" in such cases). <tt>T</tt> must be a subclass of <a href="qobject.html">QObject</a>.</p>
<p>Guarded pointers are useful whenever you need to store a pointer to a <a href="qobject.html">QObject</a> that is owned by someone else, and therefore might be destroyed while you still hold a reference to it. You can safely test the pointer for validity.</p>
<p>Qt also provides <a href="qsharedpointer.html">QSharedPointer</a>, an implementation of a reference-counted shared pointer object, which can be used to maintain a collection of references to an individual pointer.</p>
<p>Example:</p>
<pre class="cpp"> <span class="type">QPointer</span><span class="operator"><</span><span class="type"><a href="qlabel.html">QLabel</a></span><span class="operator">></span> label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
label<span class="operator">-</span><span class="operator">></span>setText(<span class="string">"&Status:"</span>);
...
<span class="keyword">if</span> (label)
label<span class="operator">-</span><span class="operator">></span>show();</pre>
<p>If the <a href="qlabel.html">QLabel</a> is deleted in the meantime, the <tt>label</tt> variable will hold 0 instead of an invalid address, and the last line will never be executed.</p>
<p>The functions and operators available with a QPointer are the same as those available with a normal unguarded pointer, except the pointer arithmetic operators (<tt>+</tt>, <tt>-</tt>, <tt>++</tt>, and <tt>--</tt>), which are normally used only with arrays of objects.</p>
<p>Use QPointers like normal pointers and you will not need to read this class documentation.</p>
<p>For creating guarded pointers, you can construct or assign to them from a T* or from another guarded pointer of the same type. You can compare them with each other using operator==() and operator!=(), or test for 0 with <a href="qpointer.html#isNull">isNull</a>(). You can dereference them using either the <tt>*x</tt> or the <tt>x->member</tt> notation.</p>
<p>A guarded pointer will automatically cast to a <tt>T</tt> *, so you can freely mix guarded and unguarded pointers. This means that if you have a QPointer<<a href="qwidget.html">QWidget</a>>, you can pass it to a function that requires a <a href="qwidget.html">QWidget</a> *. For this reason, it is of little value to declare functions to take a QPointer as a parameter; just use normal pointers. Use a QPointer when you are storing a pointer over time.</p>
<p>Note that class <tt>T</tt> must inherit <a href="qobject.html">QObject</a>, or a compilation or link error will result.</p>
</div>
<p><b>See also </b><a href="qsharedpointer.html">QSharedPointer</a>, <a href="qweakpointer.html">QWeakPointer</a>, <a href="qobject.html">QObject</a>, and <a href="qobjectcleanuphandler.html">QObjectCleanupHandler</a>.</p>
<!-- @@@QPointer -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QPointer[overload1]$$$QPointer -->
<h3 class="fn"><a name="QPointer"></a>QPointer::<span class="name">QPointer</span> ()</h3>
<p>Constructs a 0 guarded pointer.</p>
<p><b>See also </b><a href="qpointer.html#isNull">isNull</a>().</p>
<!-- @@@QPointer -->
<!-- $$$QPointer$$$QPointerT* -->
<h3 class="fn"><a name="QPointer-2"></a>QPointer::<span class="name">QPointer</span> ( <span class="type">T</span> * <i>p</i> )</h3>
<p>Constructs a guarded pointer that points to same object that <i>p</i> points to.</p>
<!-- @@@QPointer -->
<!-- $$$QPointer$$$QPointerconstQPointer<T>& -->
<h3 class="fn"><a name="QPointer-3"></a>QPointer::<span class="name">QPointer</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Copies one guarded pointer from another. The constructed guarded pointer points to the same object that <i>p</i> points to (which may be 0).</p>
<!-- @@@QPointer -->
<!-- $$$~QPointer[overload1]$$$~QPointer -->
<h3 class="fn"><a name="dtor.QPointer"></a>QPointer::<span class="name">~QPointer</span> ()</h3>
<p>Destroys the guarded pointer. Just like a normal pointer, destroying a guarded pointer does <i>not</i> destroy the object being pointed to.</p>
<!-- @@@~QPointer -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn"><a name="data"></a><span class="type">T</span> * QPointer::<span class="name">data</span> () const</h3>
<p>Returns the pointer to the object being guarded.</p>
<p>This function was introduced in Qt 4.4.</p>
<!-- @@@data -->
<!-- $$$isNull[overload1]$$$isNull -->
<h3 class="fn"><a name="isNull"></a><span class="type">bool</span> QPointer::<span class="name">isNull</span> () const</h3>
<p>Returns <tt>true</tt> if the referenced object has been destroyed or if there is no referenced object; otherwise returns false.</p>
<!-- @@@isNull -->
<!-- $$$operator T *[overload1]$$$operator T * -->
<h3 class="fn"><a name="operator-T--2a"></a>QPointer::<span class="name">operator T *</span> () const</h3>
<p>Cast operator; implements pointer semantics. Because of this function you can pass a <a href="qpointer.html">QPointer</a><T> to a function where a T* is required.</p>
<!-- @@@operator T * -->
<!-- $$$operator*[overload1]$$$operator* -->
<h3 class="fn"><a name="operator-2a"></a><span class="type">T</span> & QPointer::<span class="name">operator*</span> () const</h3>
<p>Dereference operator; implements pointer semantics. Just use this operator as you would with a normal C++ pointer.</p>
<!-- @@@operator* -->
<!-- $$$operator->[overload1]$$$operator-> -->
<h3 class="fn"><a name="operator--gt"></a><span class="type">T</span> * QPointer::<span class="name">operator-></span> () const</h3>
<p>Overloaded arrow operator; implements pointer semantics. Just use this operator as you would with a normal C++ pointer.</p>
<!-- @@@operator-> -->
<!-- $$$operator=[overload1]$$$operator=constQPointer<T>& -->
<h3 class="fn"><a name="operator-eq"></a><span class="type">QPointer</span><<span class="type">T</span>> & QPointer::<span class="name">operator=</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Assignment operator. This guarded pointer will now point to the same object that <i>p</i> points to.</p>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=T* -->
<h3 class="fn"><a name="operator-eq-2"></a><span class="type">QPointer</span><<span class="type">T</span>> & QPointer::<span class="name">operator=</span> ( <span class="type">T</span> * <i>p</i> )</h3>
<p>Assignment operator. This guarded pointer will now point to the same object that <i>p</i> points to.</p>
<!-- @@@operator= -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$operator!=[overload1]$$$operator!=constT*constQPointer<T>& -->
<h3 class="fn"><a name="operator-not-eq"></a><span class="type">bool</span> <span class="name">operator!=</span> ( const <span class="type">T</span> * <i>o</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Inequality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are not pointing to the same object, otherwise returns false.</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQPointer<T>&constT* -->
<h3 class="fn"><a name="operator-not-eq-2"></a><span class="type">bool</span> <span class="name">operator!=</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i>, const <span class="type">T</span> * <i>o</i> )</h3>
<p>Inequality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are not pointing to the same object, otherwise returns false.</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=T*constQPointer<T>& -->
<h3 class="fn"><a name="operator-not-eq-3"></a><span class="type">bool</span> <span class="name">operator!=</span> ( <span class="type">T</span> * <i>o</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Inequality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are not pointing to the same object, otherwise returns false.</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQPointer<T>&T* -->
<h3 class="fn"><a name="operator-not-eq-4"></a><span class="type">bool</span> <span class="name">operator!=</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i>, <span class="type">T</span> * <i>o</i> )</h3>
<p>Inequality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are not pointing to the same object, otherwise returns false.</p>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constQPointer<T>&constQPointer<T>& -->
<h3 class="fn"><a name="operator-not-eq-5"></a><span class="type">bool</span> <span class="name">operator!=</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p1</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p2</i> )</h3>
<p>Inequality operator. Returns true if the guarded pointers <i>p1</i> and <i>p2</i> are not pointing to the same object, otherwise returns false.</p>
<!-- @@@operator!= -->
<!-- $$$operator==[overload1]$$$operator==constT*constQPointer<T>& -->
<h3 class="fn"><a name="operator-eq-eq"></a><span class="type">bool</span> <span class="name">operator==</span> ( const <span class="type">T</span> * <i>o</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Equality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are pointing to the same object, otherwise returns false.</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQPointer<T>&constT* -->
<h3 class="fn"><a name="operator-eq-eq-2"></a><span class="type">bool</span> <span class="name">operator==</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i>, const <span class="type">T</span> * <i>o</i> )</h3>
<p>Equality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are pointing to the same object, otherwise returns false.</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==T*constQPointer<T>& -->
<h3 class="fn"><a name="operator-eq-eq-3"></a><span class="type">bool</span> <span class="name">operator==</span> ( <span class="type">T</span> * <i>o</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i> )</h3>
<p>Equality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are pointing to the same object, otherwise returns false.</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQPointer<T>&T* -->
<h3 class="fn"><a name="operator-eq-eq-4"></a><span class="type">bool</span> <span class="name">operator==</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p</i>, <span class="type">T</span> * <i>o</i> )</h3>
<p>Equality operator. Returns true if <i>o</i> and the guarded pointer <i>p</i> are pointing to the same object, otherwise returns false.</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constQPointer<T>&constQPointer<T>& -->
<h3 class="fn"><a name="operator-eq-eq-5"></a><span class="type">bool</span> <span class="name">operator==</span> ( const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p1</i>, const <span class="type">QPointer</span><<span class="type">T</span>> & <i>p2</i> )</h3>
<p>Equality operator. Returns true if the guarded pointers <i>p1</i> and <i>p2</i> are pointing to the same object, otherwise returns false.</p>
<!-- @@@operator== -->
</div>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. 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>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
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>
</body>
</html>
|