1QGuardedPtr(3qt)                                              QGuardedPtr(3qt)
2
3
4

NAME

6       QGuardedPtr - Template class that provides guarded pointers to QObjects
7

SYNOPSIS

9       #include <qguardedptr.h>
10
11   Public Members
12       QGuardedPtr ()
13       QGuardedPtr ( T * p )
14       QGuardedPtr ( const QGuardedPtr<T> & p )
15       ~QGuardedPtr ()
16       QGuardedPtr<T> & operator= ( const QGuardedPtr<T> & p )
17       QGuardedPtr<T> & operator= ( T * p )
18       bool operator== ( const QGuardedPtr<T> & p ) const
19       bool operator!= ( const QGuardedPtr<T> & p ) const
20       bool isNull () const
21       T * operator-> () const
22       T & operator* () const
23       operator T * () const
24

DESCRIPTION

26       The QGuardedPtr class is a template class that provides guarded
27       pointers to QObjects.
28
29       A guarded pointer, QGuardedPtr<X>, behaves like a normal C++ pointer
30       X*, except that it is automatically set to 0 when the referenced object
31       is destroyed (unlike normal C++ pointers, which become "dangling
32       pointers" in such cases). X must be a subclass of QObject.
33
34       Guarded pointers are useful whenever you need to store a pointer to a
35       QObject that is owned by someone else and therefore might be destroyed
36       while you still hold a reference to it. You can safely test the pointer
37       for validity.
38
39       Example:
40
41               QGuardedPtr<QLabel> label = new QLabel( 0, "label" );
42               label->setText( "I like guarded pointers" );
43               delete (QLabel*) label; // simulate somebody destroying the label
44               if ( label)
45                   label->show();
46               else
47                   qDebug("The label has been destroyed");
48
49       The program will output The label has been destroyed rather than
50       dereferencing an invalid address in label->show().
51
52       The functions and operators available with a QGuardedPtr are the same
53       as those available with a normal unguarded pointer, except the pointer
54       arithmetic operators (++, --, -, and +), which are normally used only
55       with arrays of objects. Use them like normal pointers and you will not
56       need to read this class documentation.
57
58       For creating guarded pointers, you can construct or assign to them from
59       an X* or from another guarded pointer of the same type. You can compare
60       them with each other using operator==() and operator!=(), or test for 0
61       with isNull(). And you can dereference them using either the *x or the
62       x->member notation.
63
64       A guarded pointer will automatically cast to an X*, so you can freely
65       mix guarded and unguarded pointers. This means that if you have a
66       QGuardedPtr<QWidget>, you can pass it to a function that requires a
67       QWidget*. For this reason, it is of little value to declare functions
68       to take a QGuardedPtr as a parameter; just use normal pointers. Use a
69       QGuardedPtr when you are storing a pointer over time.
70
71       Note again that class X must inherit QObject, or a compilation or link
72       error will result.
73
74       See also Object Model.
75

MEMBER FUNCTION DOCUMENTATION

QGuardedPtr::QGuardedPtr ()

78       Constructs a 0 guarded pointer.
79
80       See also isNull().
81

QGuardedPtr::QGuardedPtr ( T * p )

83       Constructs a guarded pointer that points to same object as p points to.
84

QGuardedPtr::QGuardedPtr ( const QGuardedPtr<T> & p )

86       Copy one guarded pointer from another. The constructed guarded pointer
87       points to the same object that p points to (which may be 0).
88

QGuardedPtr::~QGuardedPtr ()

90       Destroys the guarded pointer. Just like a normal pointer, destroying a
91       guarded pointer does not destroy the object being pointed to.
92

bool QGuardedPtr::isNull () const

94       Returns TRUE if the referenced object has been destroyed or if there is
95       no referenced object; otherwise returns FALSE.
96

QGuardedPtr::operator T * () const

98       Cast operator; implements pointer semantics. Because of this function
99       you can pass a QGuardedPtr<X> to a function where an X* is required.
100

bool QGuardedPtr::operator!= ( const QGuardedPtr<T> & p ) const

102       Inequality operator; implements pointer semantics, the negation of
103       operator==(). Returns TRUE if p and this guarded pointer are not
104       pointing to the same object; otherwise returns FALSE.
105

T & QGuardedPtr::operator* () const

107       Dereference operator; implements pointer semantics. Just use this
108       operator as you would with a normal C++ pointer.
109

T * QGuardedPtr::operator-> () const

111       Overloaded arrow operator; implements pointer semantics. Just use this
112       operator as you would with a normal C++ pointer.
113

QGuardedPtr<T> & QGuardedPtr::operator= ( const QGuardedPtr<T> & p )

115       Assignment operator. This guarded pointer then points to the same
116       object as p points to.
117

QGuardedPtr<T> & QGuardedPtr::operator= ( T * p )

119       This is an overloaded member function, provided for convenience. It
120       behaves essentially like the above function.
121
122       Assignment operator. This guarded pointer then points to the same
123       object as p points to.
124

bool QGuardedPtr::operator== ( const QGuardedPtr<T> & p ) const

126       Equality operator; implements traditional pointer semantics. Returns
127       TRUE if both p and this guarded pointer are 0, or if both p and this
128       pointer point to the same object; otherwise returns FALSE.
129
130       See also operator!=().
131
132

SEE ALSO

134       http://doc.trolltech.com/qguardedptr.html
135       http://www.trolltech.com/faq/tech.html
136
138       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
139       license file included in the distribution for a complete license
140       statement.
141

AUTHOR

143       Generated automatically from the source code.
144

BUGS

146       If you find a bug in Qt, please report it as described in
147       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
148       help you. Thank you.
149
150       The definitive Qt documentation is provided in HTML format; it is
151       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
152       web browser. This man page is provided as a convenience for those users
153       who prefer man pages, although this format is not officially supported
154       by Trolltech.
155
156       If you find errors in this manual page, please report them to qt-
157       bugs@trolltech.com.  Please include the name of the manual page
158       (qguardedptr.3qt) and the Qt version (3.3.8).
159
160
161
162Trolltech AS                    2 February 2007               QGuardedPtr(3qt)
Impressum