Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1356

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/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"><!--
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: #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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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 &lt;<a href="qguardedptr-h.html">qguardedptr.h</a>&gt;</tt>
<p><a href="qguardedptr-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QGuardedPtr"><b>QGuardedPtr</b></a> ()</div></li>
<li><div class=fn><a href="#QGuardedPtr-2"><b>QGuardedPtr</b></a> ( T&nbsp;*&nbsp;p )</div></li>
<li><div class=fn><a href="#QGuardedPtr-3"><b>QGuardedPtr</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p )</div></li>
<li><div class=fn><a href="#~QGuardedPtr"><b>~QGuardedPtr</b></a> ()</div></li>
<li><div 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 )</div></li>
<li><div class=fn>QGuardedPtr&lt;T&gt; &amp; <a href="#operator-eq-2"><b>operator=</b></a> ( T&nbsp;*&nbsp;p )</div></li>
<li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p ) const</div></li>
<li><div class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QGuardedPtr&lt;T&gt;&nbsp;&amp;&nbsp;p ) const</div></li>
<li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</div></li>
<li><div class=fn>T * <a href="#operator--gt"><b>operator-&gt;</b></a> () const</div></li>
<li><div class=fn>T &amp; <a href="#operator*"><b>operator*</b></a> () const</div></li>
<li><div class=fn><a href="#operator-T-*"><b>operator T *</b></a> () const</div></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, 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 such cases).
<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>
      QGuardedPtr&lt;QFrame&gt; label = new <a href="qlabel.html">QLabel</a>( 0,"label" );
      label-&gt;setText("I like guarded pointers");

      delete (QLabel*) label; // emulate somebody destroying the label

      if ( label)
          label-&gt;show();
      else
          <a href="qapplication.html#qDebug">qDebug</a>("The label has been destroyed");
  </pre>
 
<p> The program will output
<pre>
      The label has been destroyed
  </pre>
 
rather than dereferencing an invalid address in <tt>label-&gt;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 for equality (==) and inequality (!=),
or test for null with <a href="#isNull">isNull</a>().  Finally, you can dereference
them using either the <tt>*x</tt> or the <tt>x-&gt;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 null guarded pointer.
<p> <p>See also <a href="#isNull">isNull</a>().

<h3 class=fn><a name="QGuardedPtr-2"></a>QGuardedPtr::QGuardedPtr ( T&nbsp;*&nbsp;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&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;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 null).

<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.

<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&nbsp;<a href="qguardedptr.html">QGuardedPtr</a>&lt;T&gt;&nbsp;&amp;&nbsp;p ) const
</h3>

<p> Inequality operator; implements pointer semantics, the negation
of operator==.  Returns TRUE if <em>p</em> and this guarded pointer are
not pointing to the same object; otherwise returns FALSE.

<h3 class=fn>T &amp; <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-&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><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 )
</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>&lt;T&gt;&nbsp;&amp; <a name="operator-eq-2"></a>QGuardedPtr::operator= ( T&nbsp;*&nbsp;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 same object as
<em>p</em> points to.

<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
</h3>

<p> Equality operator; implements traditional pointer semantics. Returns
TRUE if both <em>p</em> and this guarded pointer are null, or if both <em>p</em>
and this 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 &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 &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>