File: qguardedptr.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (146 lines) | stat: -rw-r--r-- 8,474 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QGuardedPtr Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>QGuardedPtr Class Reference</h1><br clear="all">
<p>
The QGuardedPtr class is a template class that provides guarded pointers to QObjects
<a href="#details">More...</a>
<p>
<code>#include &lt;<a href="qguardedptr-h.html">qguardedptr.h</a>&gt;</code>
<p><a href="qguardedptr-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#c99332"><b>QGuardedPtr</b></a>()</div>
<li><div class="fn"><a href="#1ab629"><b>QGuardedPtr</b></a>(T*p)</div>
<li><div class="fn"><a href="#e0fa7d"><b>QGuardedPtr</b></a>(constQGuardedPtr&lt;T&gt;&amp;p)</div>
<li><div class="fn"><a href="#17281e"><b>~QGuardedPtr</b></a>()</div>
<li><div class="fn">QGuardedPtr&lt;T&gt;&amp;<a href="#2e930e"><b>operator=</b></a>(constQGuardedPtr&lt;T&gt;&amp;p)</div>
<li><div class="fn">QGuardedPtr&lt;T&gt;&amp;<a href="#308152"><b>operator=</b></a>(T*p)</div>
<li><div class="fn">bool<a href="#5b9549"><b>operator==</b></a>(constQGuardedPtr&lt;T&gt;&amp;p)const</div>
<li><div class="fn">bool<a href="#1189cc"><b>operator!=</b></a>(constQGuardedPtr&lt;T&gt;&amp;p)const</div>
<li><div class="fn">bool<a href="#2d41ab"><b>isNull</b></a>()const</div>
<li><div class="fn">T*<a href="#851be9"><b>operator-&gt;</b></a>()const</div>
<li><div class="fn">T&amp;<a href="#096c9c"><b>operator*</b></a>()const</div>
<li><div class="fn">operator<a href=qguardedptr.html#991ebc><b>T*</b></a>()const</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QGuardedPtr class is a template class that provides guarded pointers to QObjects
<p>
A guarded pointer, QGuardedPtr&lt;<em>X</em>&gt;,
behaves like a normal C++ pointer <em>X*,</em> except that
it is automatically set to null when the referenced object is destroyed,
unlike normal C++ pointers which become "dangling pointers" in that case.
<em>X</em> must be a subclass of <a href="qobject.html">QObject</a>.
<p>Guarded pointers are useful whenever you need to store a pointer to a
QObject that is owned by someone else and therefore might be
destroyed while you still keep a reference to it. You can safely test
the pointer for validity.
<p>Example:
<pre>      <a href="qguardedptr.html">QGuardedPtr</a>&lt;<a href="qframe.html">QFrame</a>&gt; label = new <a href="qlabel.html">QLabel</a>( 0,"label" );
      label-&gt;setText("I like guarded pointers");

      delete (<a href="qlabel.html">QLabel</a>*) label; // emulate somebody destroying the label

      if ( label)
          label-&gt;show();
      else 
          <a href="qapplication.html#72e78c">qDebug</a>("The label has been destroyed");
</pre>
<p>The program will output
<pre>      The label has been destroyed
</pre>
<p>rather than dereferencing an invalid address in <code>label->show().</code>
<p>The functions and operators available with a QGuardedPtr are the same
as those available with a normal unguarded pointer, except the pointer
arithmetic operators, ++, --, -, and +, which are normally only used with
arrays of objects. Use them like normal pointers and you will not need
to read this class documentation.
<p>For creating guarded pointers, you can construct or assign to them
from an X* or from another guarded pointer of the same type. You can
compare them with each other for equality (==) and inequality (!=),
or test for null with <a href="#2d41ab">isNull</a>().  Finally, you can dereference
them using either the <code>*x</code> or the <code>x->member</code> notation.
<p>A guarded pointer will automatically cast to an X* so you can freely
mix guarded and unguarded pointers. This means that if you have a
QGuardedPtr<QWidget>, then 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 QGuardedPtr as a parameter - just use normal pointers.
Use a QGuardedPtr when you are storing a pointer over time.
<p>Note again that class <em>X</em> must inherit QObject or a compilation or link
error will result.

<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="c99332"></a>QGuardedPtr::QGuardedPtr()</h3>
<p>Constructs a null guarded pointer.
<p>See also  <a href="#2d41ab">isNull</a>().
<h3 class="fn"><a name="1ab629"></a>QGuardedPtr::QGuardedPtr(T*p)</h3>
<p>Constructs a guarded pointer that points to same object as is
pointed to by <em>p.</em>
<h3 class="fn"><a name="e0fa7d"></a>QGuardedPtr::QGuardedPtr(constQGuardedPtr&lt;T&gt;&amp;p)</h3>
<p>Copy one guarded pointer from another. The constructed guarded pointer
points to the same object that <em>p</em> pointed to (possibly null).
<h3 class="fn"><a name="17281e"></a>QGuardedPtr::~QGuardedPtr()</h3>
<p>Destructs the guarded pointer.
Note that the object <em>pointed to</em> by the pointer
is <em>not</em> destructed, just as is the case with a normal unguarded pointer.
<h3 class="fn"><a name="991ebc"></a>QGuardedPtr::operatorT*()const</h3>
<p>Cast operator, implements pointer semantics. Because of this function,
you can pass a QGuardedPtr<X> to a function where an X* is
required.
<h3 class="fn">bool<a name="2d41ab"></a>QGuardedPtr::isNull()const</h3>
<p>Returns <code>TRUE</code> if the referenced object has been destroyed or if there is
no referenced object.
<h3 class="fn">bool<a name="1189cc"></a>QGuardedPtr::operator!=(constQGuardedPtr&lt;T&gt;&amp;p)const</h3>
<p>Unequality operator, implements pointer semantics, the negation
of <a href="#5b9549">operator==</a>().
<h3 class="fn">T&amp;<a name="096c9c"></a>QGuardedPtr::operator*()const</h3>
<p>Dereference operator, implements pointer semantics. Just use this
operator as you would with a normal C++ pointer.
<h3 class="fn">T*<a name="851be9"></a>QGuardedPtr::operator-&gt;()const</h3>
<p>Overloaded arrow operator, implements pointer semantics. Just use this
operator as you would with a normal C++ pointer.
<h3 class="fn">QGuardedPtr&lt;T&gt;&amp;<a name="308152"></a>QGuardedPtr::operator=(T*p)</h3>
<p>Assignment operator.  This guarded pointer then points to same object as is
pointed to by <em>p.</em>
<h3 class="fn">QGuardedPtr&lt;T&gt;&amp;<a name="2e930e"></a>QGuardedPtr::operator=(constQGuardedPtr&lt;T&gt;&amp;p)</h3>
<p>Assignment operator. This guarded pointer then points to the same
object as does <em>p.</em>
<h3 class="fn">bool<a name="5b9549"></a>QGuardedPtr::operator==(constQGuardedPtr&lt;T&gt;&amp;p)const</h3>
<p>Equality operator, implements traditional pointer semantics: returns
TRUE if both <em>p</em> and this are null, or if both <em>p</em> and this point
to the same object.
<p>See also  <a href="#1189cc">operator!=</a>().
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright &copy; 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>