source: trunk/doc/html/qguardedptr.html@ 208

Last change on this file since 208 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.1 KB
Line 
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"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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 &lt;<a href="qguardedptr-h.html">qguardedptr.h</a>&gt;</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&nbsp;*&nbsp;p )</li>
42<li class=fn><a href="#QGuardedPtr-3"><b>QGuardedPtr</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p )</li>
43<li class=fn><a href="#~QGuardedPtr"><b>~QGuardedPtr</b></a> ()</li>
44<li class=fn>QGuardedPtr&lt;T&gt; &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p )</li>
45<li class=fn>QGuardedPtr&lt;T&gt; &amp; <a href="#operator-eq-2"><b>operator=</b></a> ( T&nbsp;*&nbsp;p )</li>
46<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p ) const</li>
47<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;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-&gt;</b></a> () const</li>
50<li class=fn>T &amp; <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
56The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
57<p>
58
59<p> A guarded pointer, <tt>QGuardedPtr&lt;X&gt;</tt>, behaves like a normal C++
60pointer <tt>X*</tt>, except that it is automatically set to 0 when
61the referenced object is destroyed (unlike normal C++ pointers,
62which become "dangling pointers" in such cases). <tt>X</tt> must be a
63subclass of <a href="qobject.html">QObject</a>.
64<p> Guarded pointers are useful whenever you need to store a pointer
65to a QObject that is owned by someone else and therefore might be
66destroyed while you still hold a reference to it. You can safely
67test the pointer for validity.
68<p> Example:
69<pre>
70 QGuardedPtr&lt;QLabel&gt; label = new <a href="qlabel.html">QLabel</a>( 0, "label" );
71 label-&gt;setText( "I like guarded pointers" );
72
73 delete (QLabel*) label; // simulate somebody destroying the label
74
75 if ( label)
76 label-&gt;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
82than dereferencing an invalid address in <tt>label-&gt;show()</tt>.
83<p> The functions and operators available with a QGuardedPtr are the
84same as those available with a normal unguarded pointer, except
85the pointer arithmetic operators (++, --, -, and +), which are
86normally used only with arrays of objects. Use them like normal
87pointers and you will not need to read this class documentation.
88<p> For creating guarded pointers, you can construct or assign to them
89from an X* or from another guarded pointer of the same type. You
90can 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
92them using either the <tt>*x</tt> or the <tt>x-&gt;member</tt> notation.
93<p> A guarded pointer will automatically cast to an X*, so you can
94freely mix guarded and unguarded pointers. This means that if you
95have a QGuardedPtr<QWidget>, you can pass it to a function that
96requires a <a href="qwidget.html">QWidget</a>*. For this reason, it is of little value to
97declare functions to take a QGuardedPtr as a parameter; just use
98normal pointers. Use a QGuardedPtr when you are storing a pointer
99over time.
100<p> Note again that class <em>X</em> must inherit <a href="qobject.html">QObject</a>, or a compilation
101or 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&nbsp;*&nbsp;p )
112</h3>
113
114<p> Constructs a guarded pointer that points to same object as <em>p</em>
115points to.
116
117<h3 class=fn><a name="QGuardedPtr-3"></a>QGuardedPtr::QGuardedPtr ( const&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;p )
118</h3>
119
120<p> Copy one guarded pointer from another. The constructed guarded
121pointer points to the same object that <em>p</em> points to (which may
122be 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,
128destroying a guarded pointer does <em>not</em> destroy the object being
129pointed 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
135there 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
141function you can pass a QGuardedPtr&lt;X&gt; to a function where an X*
142is required.
143
144<h3 class=fn>bool <a name="operator!-eq"></a>QGuardedPtr::operator!= ( const&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;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
149not pointing to the same object; otherwise returns FALSE.
150
151<h3 class=fn>T &amp; <a name="operator*"></a>QGuardedPtr::operator* () const
152</h3>
153
154<p> Dereference operator; implements pointer semantics. Just use this
155operator as you would with a normal C++ pointer.
156
157<h3 class=fn>T * <a name="operator--gt"></a>QGuardedPtr::operator-&gt; () const
158</h3>
159
160<p> Overloaded arrow operator; implements pointer semantics. Just use
161this operator as you would with a normal C++ pointer.
162
163<h3 class=fn><a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp; <a name="operator-eq"></a>QGuardedPtr::operator= ( const&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;p )
164</h3>
165
166<p> Assignment operator. This guarded pointer then points to the same
167object as <em>p</em> points to.
168
169<h3 class=fn><a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp; <a name="operator-eq-2"></a>QGuardedPtr::operator= ( T&nbsp;*&nbsp;p )
170</h3>
171This 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
173object as <em>p</em> points to.
174
175<h3 class=fn>bool <a name="operator-eq-eq"></a>QGuardedPtr::operator== ( const&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;p ) const
176</h3>
177
178<p> Equality operator; implements traditional pointer semantics.
179Returns TRUE if both <em>p</em> and this guarded pointer are 0, or if
180both <em>p</em> and this pointer point to the same object; otherwise
181returns FALSE.
182<p> <p>See also <a href="#operator!-eq">operator!=</a>().
183
184<!-- eof -->
185<hr><p>
186This file is part of the <a href="index.html">Qt toolkit</a>.
187Copyright &copy; 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 &copy; 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>
Note: See TracBrowser for help on using the repository browser.