You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
8.9 KiB
195 lines
8.9 KiB
14 years ago
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qguardedptr.cpp:40 -->
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
<title>QGuardedPtr Class</title>
|
||
|
<style type="text/css"><!--
|
||
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
||
|
a:link { color: #004faf; text-decoration: none }
|
||
|
a:visited { color: #672967; text-decoration: none }
|
||
|
body { background: #ffffff; color: black; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||
|
<tr bgcolor="#E5E5E5">
|
||
|
<td valign=center>
|
||
|
<a href="index.html">
|
||
|
<font color="#004faf">Home</font></a>
|
||
|
| <a href="classes.html">
|
||
|
<font color="#004faf">All Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped Classes</font></a>
|
||
|
| <a href="functions.html">
|
||
|
<font color="#004faf">Functions</font></a>
|
||
|
</td>
|
||
|
<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>
|
||
|
|
||
|
<p>The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
|
||
|
<a href="#details">More...</a>
|
||
|
<p><tt>#include <<a href="qguardedptr-h.html">qguardedptr.h</a>></tt>
|
||
|
<p><a href="qguardedptr-members.html">List of all member functions.</a>
|
||
|
<h2>Public Members</h2>
|
||
|
<ul>
|
||
|
<li class=fn><a href="#QGuardedPtr"><b>QGuardedPtr</b></a> ()</li>
|
||
|
<li class=fn><a href="#QGuardedPtr-2"><b>QGuardedPtr</b></a> ( T * p )</li>
|
||
|
<li class=fn><a href="#QGuardedPtr-3"><b>QGuardedPtr</b></a> ( const QGuardedPtr<T> & p )</li>
|
||
|
<li class=fn><a href="#~QGuardedPtr"><b>~QGuardedPtr</b></a> ()</li>
|
||
|
<li class=fn>QGuardedPtr<T> & <a href="#operator-eq"><b>operator=</b></a> ( const QGuardedPtr<T> & p )</li>
|
||
|
<li class=fn>QGuardedPtr<T> & <a href="#operator-eq-2"><b>operator=</b></a> ( T * p )</li>
|
||
|
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QGuardedPtr<T> & p ) const</li>
|
||
|
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QGuardedPtr<T> & p ) const</li>
|
||
|
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
|
||
|
<li class=fn>T * <a href="#operator--gt"><b>operator-></b></a> () const</li>
|
||
|
<li class=fn>T & <a href="#operator*"><b>operator*</b></a> () const</li>
|
||
|
<li class=fn><a href="#operator-T-*"><b>operator T *</b></a> () const</li>
|
||
|
</ul>
|
||
|
<hr><a name="details"></a><h2>Detailed Description</h2>
|
||
|
|
||
|
|
||
|
The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
|
||
|
<p>
|
||
|
|
||
|
<p> A guarded pointer, <tt>QGuardedPtr<X></tt>, behaves like a normal C++
|
||
|
pointer <tt>X*</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>X</tt> 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 hold a reference to it. You can safely
|
||
|
test the pointer for validity.
|
||
|
<p> Example:
|
||
|
<pre>
|
||
|
QGuardedPtr<QLabel> label = new <a href="qlabel.html">QLabel</a>( 0, "label" );
|
||
|
label->setText( "I like guarded pointers" );
|
||
|
|
||
|
delete (QLabel*) label; // simulate somebody destroying the label
|
||
|
|
||
|
if ( label)
|
||
|
label->show();
|
||
|
else
|
||
|
<a href="qapplication.html#qDebug">qDebug</a>("The label has been destroyed");
|
||
|
</pre>
|
||
|
|
||
|
<p> The program will output <tt>The label has been destroyed</tt> rather
|
||
|
than dereferencing an invalid address in <tt>label->show()</tt>.
|
||
|
<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 used only 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 using <a href="#operator-eq-eq">operator==</a>() and
|
||
|
<a href="#operator!-eq">operator!=</a>(), or test for 0 with <a href="#isNull">isNull</a>(). And you can dereference
|
||
|
them using either the <tt>*x</tt> or the <tt>x->member</tt> 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>, 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 <a href="qobject.html">QObject</a>, or a compilation
|
||
|
or link error will result.
|
||
|
<p>See also <a href="objectmodel.html">Object Model</a>.
|
||
|
|
||
|
<hr><h2>Member Function Documentation</h2>
|
||
|
<h3 class=fn><a name="QGuardedPtr"></a>QGuardedPtr::QGuardedPtr ()
|
||
|
</h3>
|
||
|
|
||
|
<p> Constructs a 0 guarded pointer.
|
||
|
<p> <p>See also <a href="#isNull">isNull</a>().
|
||
|
|
||
|
<h3 class=fn><a name="QGuardedPtr-2"></a>QGuardedPtr::QGuardedPtr ( T * p )
|
||
|
</h3>
|
||
|
|
||
|
<p> Constructs a guarded pointer that points to same object as <em>p</em>
|
||
|
points to.
|
||
|
|
||
|
<h3 class=fn><a name="QGuardedPtr-3"></a>QGuardedPtr::QGuardedPtr ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p )
|
||
|
</h3>
|
||
|
|
||
|
<p> Copy one guarded pointer from another. The constructed guarded
|
||
|
pointer points to the same object that <em>p</em> points to (which may
|
||
|
be 0).
|
||
|
|
||
|
<h3 class=fn><a name="~QGuardedPtr"></a>QGuardedPtr::~QGuardedPtr ()
|
||
|
</h3>
|
||
|
|
||
|
<p> Destroys the guarded pointer. Just like a normal pointer,
|
||
|
destroying a guarded pointer does <em>not</em> destroy the object being
|
||
|
pointed to.
|
||
|
|
||
|
<h3 class=fn>bool <a name="isNull"></a>QGuardedPtr::isNull () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Returns <tt>TRUE</tt> if the referenced object has been destroyed or if
|
||
|
there is no referenced object; otherwise returns FALSE.
|
||
|
|
||
|
<h3 class=fn><a name="operator-T-*"></a>QGuardedPtr::operator T * () 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="operator!-eq"></a>QGuardedPtr::operator!= ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p ) const
|
||
|
</h3>
|
||
|
|
||
|
<p> Inequality operator; implements pointer semantics, the negation of
|
||
|
<a href="#operator-eq-eq">operator==</a>(). Returns TRUE if <em>p</em> and this guarded pointer are
|
||
|
not pointing to the same object; otherwise returns FALSE.
|
||
|
|
||
|
<h3 class=fn>T & <a name="operator*"></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="operator--gt"></a>QGuardedPtr::operator-> () const
|
||
|
</h3>
|
||
|
|
||
|
<p> Overloaded arrow operator; implements pointer semantics. Just use
|
||
|
this operator as you would with a normal C++ pointer.
|
||
|
|
||
|
<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 )
|
||
|
</h3>
|
||
|
|
||
|
<p> Assignment operator. This guarded pointer then points to the same
|
||
|
object as <em>p</em> points to.
|
||
|
|
||
|
<h3 class=fn><a href="qguardedptr.html">QGuardedPtr</a><T> & <a name="operator-eq-2"></a>QGuardedPtr::operator= ( T * p )
|
||
|
</h3>
|
||
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
||
|
<p> Assignment operator. This guarded pointer then points to the same
|
||
|
object as <em>p</em> points to.
|
||
|
|
||
|
<h3 class=fn>bool <a name="operator-eq-eq"></a>QGuardedPtr::operator== ( const <a href="qguardedptr.html">QGuardedPtr</a><T> & p ) const
|
||
|
</h3>
|
||
|
|
||
|
<p> Equality operator; implements traditional pointer semantics.
|
||
|
Returns TRUE if both <em>p</em> and this guarded pointer are 0, or if
|
||
|
both <em>p</em> and this pointer point to the same object; otherwise
|
||
|
returns FALSE.
|
||
|
<p> <p>See also <a href="#operator!-eq">operator!=</a>().
|
||
|
|
||
|
<!-- eof -->
|
||
|
<hr><p>
|
||
|
This file is part of the <a href="index.html">Qt toolkit</a>.
|
||
|
Copyright © 1995-2007
|
||
|
<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 © 2007
|
||
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
||
|
<td align=right><div align=right>Qt 3.3.8</div>
|
||
|
</table></div></address></body>
|
||
|
</html>
|