summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqguardedptr.3qt
blob: c2823a27b2ead249a4ff8a54677692c57f0a4191 (plain)
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
147
148
'\" t
.TH TQGuardedPtr 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQGuardedPtr \- Template class that provides guarded pointers to TQObjects
.SH SYNOPSIS
\fC#include <tqguardedptr.h>\fR
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQGuardedPtr\fR ()"
.br
.ti -1c
.BI "\fBTQGuardedPtr\fR ( T * p )"
.br
.ti -1c
.BI "\fBTQGuardedPtr\fR ( const TQGuardedPtr<T> & p )"
.br
.ti -1c
.BI "\fB~TQGuardedPtr\fR ()"
.br
.ti -1c
.BI "TQGuardedPtr<T> & \fBoperator=\fR ( const TQGuardedPtr<T> & p )"
.br
.ti -1c
.BI "TQGuardedPtr<T> & \fBoperator=\fR ( T * p )"
.br
.ti -1c
.BI "bool \fBoperator==\fR ( const TQGuardedPtr<T> & p ) const"
.br
.ti -1c
.BI "bool \fBoperator!=\fR ( const TQGuardedPtr<T> & p ) const"
.br
.ti -1c
.BI "bool \fBisNull\fR () const"
.br
.ti -1c
.BI "T * \fBoperator->\fR () const"
.br
.ti -1c
.BI "T & \fBoperator*\fR () const"
.br
.ti -1c
.BI "\fBoperator T *\fR () const"
.br
.in -1c
.SH DESCRIPTION
The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects.
.PP
A guarded pointer, \fCTQGuardedPtr<X>\fR, behaves like a normal C++ pointer \fCX*\fR, 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). \fCX\fR must be a subclass of TQObject.
.PP
Guarded pointers are useful whenever you need to store a pointer to a TQObject 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.
.PP
Example:
.PP
.nf
.br
        TQGuardedPtr<TQLabel> label = new TQLabel( 0, "label" );
.br
        label->setText( "I like guarded pointers" );
.br
.br
        delete (TQLabel*) label; // simulate somebody destroying the label
.br
.br
        if ( label)
.br
            label->show();
.br
        else
.br
            tqDebug("The label has been destroyed");
.br
.fi
.PP
The program will output \fCThe label has been destroyed\fR rather than dereferencing an invalid address in \fClabel->show()\fR.
.PP
The functions and operators available with a TQGuardedPtr 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.
.PP
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 operator==() and operator!=(), or test for 0 with isNull(). And you can dereference them using either the \fC*x\fR or the \fCx->member\fR notation.
.PP
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 TQGuardedPtr<TQWidget>, you can pass it to a function that requires a TQWidget*. For this reason, it is of little value to declare functions to take a TQGuardedPtr as a parameter; just use normal pointers. Use a TQGuardedPtr when you are storing a pointer over time.
.PP
Note again that class \fIX\fR must inherit TQObject, or a compilation or link error will result.
.PP
See also Object Model.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQGuardedPtr::TQGuardedPtr ()"
Constructs a 0 guarded pointer.
.PP
See also isNull().
.SH "TQGuardedPtr::TQGuardedPtr ( T * p )"
Constructs a guarded pointer that points to same object as \fIp\fR points to.
.SH "TQGuardedPtr::TQGuardedPtr ( const TQGuardedPtr<T> & p )"
Copy one guarded pointer from another. The constructed guarded pointer points to the same object that \fIp\fR points to (which may be 0).
.SH "TQGuardedPtr::~TQGuardedPtr ()"
Destroys the guarded pointer. Just like a normal pointer, destroying a guarded pointer does \fInot\fR destroy the object being pointed to.
.SH "bool TQGuardedPtr::isNull () const"
Returns \fCTRUE\fR if the referenced object has been destroyed or if there is no referenced object; otherwise returns FALSE.
.SH "TQGuardedPtr::operator T * () const"
Cast operator; implements pointer semantics. Because of this function you can pass a TQGuardedPtr<X> to a function where an X* is required.
.SH "bool TQGuardedPtr::operator!= ( const TQGuardedPtr<T> & p ) const"
Inequality operator; implements pointer semantics, the negation of operator==(). Returns TRUE if \fIp\fR and this guarded pointer are not pointing to the same object; otherwise returns FALSE.
.SH "T & TQGuardedPtr::operator* () const"
Dereference operator; implements pointer semantics. Just use this operator as you would with a normal C++ pointer.
.SH "T * TQGuardedPtr::operator-> () const"
Overloaded arrow operator; implements pointer semantics. Just use this operator as you would with a normal C++ pointer.
.SH "TQGuardedPtr<T> & TQGuardedPtr::operator= ( const TQGuardedPtr<T> & p )"
Assignment operator. This guarded pointer then points to the same object as \fIp\fR points to.
.SH "TQGuardedPtr<T> & TQGuardedPtr::operator= ( T * p )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Assignment operator. This guarded pointer then points to the same object as \fIp\fR points to.
.SH "bool TQGuardedPtr::operator== ( const TQGuardedPtr<T> & p ) const"
Equality operator; implements traditional pointer semantics. Returns TRUE if both \fIp\fR and this guarded pointer are 0, or if both \fIp\fR and this pointer point to the same object; otherwise returns FALSE.
.PP
See also operator!=().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqguardedptr.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR [email protected] .
Please include the name of the manual page (tqguardedptr.3qt) and the Qt
version (3.3.8).