[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qguardedptr.cpp:40 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>QGuardedPtr Class</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QGuardedPtr Class Reference</h1>
|
---|
| 33 |
|
---|
| 34 | <p>The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
|
---|
| 35 | <a href="#details">More...</a>
|
---|
| 36 | <p><tt>#include <<a href="qguardedptr-h.html">qguardedptr.h</a>></tt>
|
---|
| 37 | <p><a href="qguardedptr-members.html">List of all member functions.</a>
|
---|
| 38 | <h2>Public Members</h2>
|
---|
| 39 | <ul>
|
---|
| 40 | <li class=fn><a href="#QGuardedPtr"><b>QGuardedPtr</b></a> ()</li>
|
---|
| 41 | <li class=fn><a href="#QGuardedPtr-2"><b>QGuardedPtr</b></a> ( T * p )</li>
|
---|
| 42 | <li class=fn><a href="#QGuardedPtr-3"><b>QGuardedPtr</b></a> ( const QGuardedPtr<T> & p )</li>
|
---|
| 43 | <li class=fn><a href="#~QGuardedPtr"><b>~QGuardedPtr</b></a> ()</li>
|
---|
| 44 | <li class=fn>QGuardedPtr<T> & <a href="#operator-eq"><b>operator=</b></a> ( const QGuardedPtr<T> & p )</li>
|
---|
| 45 | <li class=fn>QGuardedPtr<T> & <a href="#operator-eq-2"><b>operator=</b></a> ( T * p )</li>
|
---|
| 46 | <li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QGuardedPtr<T> & p ) const</li>
|
---|
| 47 | <li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QGuardedPtr<T> & p ) const</li>
|
---|
| 48 | <li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
|
---|
| 49 | <li class=fn>T * <a href="#operator--gt"><b>operator-></b></a> () const</li>
|
---|
| 50 | <li class=fn>T & <a href="#operator*"><b>operator*</b></a> () const</li>
|
---|
| 51 | <li class=fn><a href="#operator-T-*"><b>operator T *</b></a> () const</li>
|
---|
| 52 | </ul>
|
---|
| 53 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
|
---|
| 57 | <p>
|
---|
| 58 |
|
---|
| 59 | <p> A guarded pointer, <tt>QGuardedPtr<X></tt>, behaves like a normal C++
|
---|
| 60 | pointer <tt>X*</tt>, except that it is automatically set to 0 when
|
---|
| 61 | the referenced object is destroyed (unlike normal C++ pointers,
|
---|
| 62 | which become "dangling pointers" in such cases). <tt>X</tt> must be a
|
---|
| 63 | subclass of <a href="qobject.html">QObject</a>.
|
---|
| 64 | <p> Guarded pointers are useful whenever you need to store a pointer
|
---|
| 65 | to a QObject that is owned by someone else and therefore might be
|
---|
| 66 | destroyed while you still hold a reference to it. You can safely
|
---|
| 67 | test the pointer for validity.
|
---|
| 68 | <p> Example:
|
---|
| 69 | <pre>
|
---|
| 70 | QGuardedPtr<QLabel> label = new <a href="qlabel.html">QLabel</a>( 0, "label" );
|
---|
| 71 | label->setText( "I like guarded pointers" );
|
---|
| 72 |
|
---|
| 73 | delete (QLabel*) label; // simulate somebody destroying the label
|
---|
| 74 |
|
---|
| 75 | if ( label)
|
---|
| 76 | label->show();
|
---|
| 77 | else
|
---|
| 78 | <a href="qapplication.html#qDebug">qDebug</a>("The label has been destroyed");
|
---|
| 79 | </pre>
|
---|
| 80 |
|
---|
| 81 | <p> The program will output <tt>The label has been destroyed</tt> rather
|
---|
| 82 | than dereferencing an invalid address in <tt>label->show()</tt>.
|
---|
| 83 | <p> The functions and operators available with a QGuardedPtr are the
|
---|
| 84 | same as those available with a normal unguarded pointer, except
|
---|
| 85 | the pointer arithmetic operators (++, --, -, and +), which are
|
---|
| 86 | normally used only with arrays of objects. Use them like normal
|
---|
| 87 | pointers and you will not need to read this class documentation.
|
---|
| 88 | <p> For creating guarded pointers, you can construct or assign to them
|
---|
| 89 | from an X* or from another guarded pointer of the same type. You
|
---|
| 90 | can compare them with each other using <a href="#operator-eq-eq">operator==</a>() and
|
---|
| 91 | <a href="#operator!-eq">operator!=</a>(), or test for 0 with <a href="#isNull">isNull</a>(). And you can dereference
|
---|
| 92 | them using either the <tt>*x</tt> or the <tt>x->member</tt> notation.
|
---|
| 93 | <p> A guarded pointer will automatically cast to an X*, so you can
|
---|
| 94 | freely mix guarded and unguarded pointers. This means that if you
|
---|
| 95 | have a QGuardedPtr<QWidget>, you can pass it to a function that
|
---|
| 96 | requires a <a href="qwidget.html">QWidget</a>*. For this reason, it is of little value to
|
---|
| 97 | declare functions to take a QGuardedPtr as a parameter; just use
|
---|
| 98 | normal pointers. Use a QGuardedPtr when you are storing a pointer
|
---|
| 99 | over time.
|
---|
| 100 | <p> Note again that class <em>X</em> must inherit <a href="qobject.html">QObject</a>, or a compilation
|
---|
| 101 | or link error will result.
|
---|
| 102 | <p>See also <a href="objectmodel.html">Object Model</a>.
|
---|
| 103 |
|
---|
| 104 | <hr><h2>Member Function Documentation</h2>
|
---|
| 105 | <h3 class=fn><a name="QGuardedPtr"></a>QGuardedPtr::QGuardedPtr ()
|
---|
| 106 | </h3>
|
---|
| 107 |
|
---|
| 108 | <p> Constructs a 0 guarded pointer.
|
---|
| 109 | <p> <p>See also <a href="#isNull">isNull</a>().
|
---|
| 110 |
|
---|
| 111 | <h3 class=fn><a name="QGuardedPtr-2"></a>QGuardedPtr::QGuardedPtr ( T * p )
|
---|
| 112 | </h3>
|
---|
| 113 |
|
---|
| 114 | <p> Constructs a guarded pointer that points to same object as <em>p</em>
|
---|
| 115 | points to.
|
---|
| 116 |
|
---|
| 117 | <h3 class=fn><a name="QGuardedPtr-3"></a>QGuardedPtr::QGuardedPtr ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p )
|
---|
| 118 | </h3>
|
---|
| 119 |
|
---|
| 120 | <p> Copy one guarded pointer from another. The constructed guarded
|
---|
| 121 | pointer points to the same object that <em>p</em> points to (which may
|
---|
| 122 | be 0).
|
---|
| 123 |
|
---|
| 124 | <h3 class=fn><a name="~QGuardedPtr"></a>QGuardedPtr::~QGuardedPtr ()
|
---|
| 125 | </h3>
|
---|
| 126 |
|
---|
| 127 | <p> Destroys the guarded pointer. Just like a normal pointer,
|
---|
| 128 | destroying a guarded pointer does <em>not</em> destroy the object being
|
---|
| 129 | pointed to.
|
---|
| 130 |
|
---|
| 131 | <h3 class=fn>bool <a name="isNull"></a>QGuardedPtr::isNull () const
|
---|
| 132 | </h3>
|
---|
| 133 |
|
---|
| 134 | <p> Returns <tt>TRUE</tt> if the referenced object has been destroyed or if
|
---|
| 135 | there is no referenced object; otherwise returns FALSE.
|
---|
| 136 |
|
---|
| 137 | <h3 class=fn><a name="operator-T-*"></a>QGuardedPtr::operator T * () const
|
---|
| 138 | </h3>
|
---|
| 139 |
|
---|
| 140 | <p> Cast operator; implements pointer semantics. Because of this
|
---|
| 141 | function you can pass a QGuardedPtr<X> to a function where an X*
|
---|
| 142 | is required.
|
---|
| 143 |
|
---|
| 144 | <h3 class=fn>bool <a name="operator!-eq"></a>QGuardedPtr::operator!= ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p ) const
|
---|
| 145 | </h3>
|
---|
| 146 |
|
---|
| 147 | <p> Inequality operator; implements pointer semantics, the negation of
|
---|
| 148 | <a href="#operator-eq-eq">operator==</a>(). Returns TRUE if <em>p</em> and this guarded pointer are
|
---|
| 149 | not pointing to the same object; otherwise returns FALSE.
|
---|
| 150 |
|
---|
| 151 | <h3 class=fn>T & <a name="operator*"></a>QGuardedPtr::operator* () const
|
---|
| 152 | </h3>
|
---|
| 153 |
|
---|
| 154 | <p> Dereference operator; implements pointer semantics. Just use this
|
---|
| 155 | operator as you would with a normal C++ pointer.
|
---|
| 156 |
|
---|
| 157 | <h3 class=fn>T * <a name="operator--gt"></a>QGuardedPtr::operator-> () const
|
---|
| 158 | </h3>
|
---|
| 159 |
|
---|
| 160 | <p> Overloaded arrow operator; implements pointer semantics. Just use
|
---|
| 161 | this operator as you would with a normal C++ pointer.
|
---|
| 162 |
|
---|
| 163 | <h3 class=fn><a href="qguardedptr.html">QGuardedPtr</a><T> & <a name="operator-eq"></a>QGuardedPtr::operator= ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p )
|
---|
| 164 | </h3>
|
---|
| 165 |
|
---|
| 166 | <p> Assignment operator. This guarded pointer then points to the same
|
---|
| 167 | object as <em>p</em> points to.
|
---|
| 168 |
|
---|
| 169 | <h3 class=fn><a href="qguardedptr.html">QGuardedPtr</a><T> & <a name="operator-eq-2"></a>QGuardedPtr::operator= ( T * p )
|
---|
| 170 | </h3>
|
---|
| 171 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 172 | <p> Assignment operator. This guarded pointer then points to the same
|
---|
| 173 | object as <em>p</em> points to.
|
---|
| 174 |
|
---|
| 175 | <h3 class=fn>bool <a name="operator-eq-eq"></a>QGuardedPtr::operator== ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p ) const
|
---|
| 176 | </h3>
|
---|
| 177 |
|
---|
| 178 | <p> Equality operator; implements traditional pointer semantics.
|
---|
| 179 | Returns TRUE if both <em>p</em> and this guarded pointer are 0, or if
|
---|
| 180 | both <em>p</em> and this pointer point to the same object; otherwise
|
---|
| 181 | returns FALSE.
|
---|
| 182 | <p> <p>See also <a href="#operator!-eq">operator!=</a>().
|
---|
| 183 |
|
---|
| 184 | <!-- eof -->
|
---|
| 185 | <hr><p>
|
---|
| 186 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 187 | Copyright © 1995-2007
|
---|
| 188 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
| 189 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 190 | <td>Copyright © 2007
|
---|
| 191 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 192 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 193 | </table></div></address></body>
|
---|
| 194 | </html>
|
---|