1QPtrCollection(3qt) QPtrCollection(3qt)
2
3
4
6 QPtrCollection - The base class of most pointer-based Qt collections
7
9 All the functions in this class are reentrant when Qt is built with
10 thread support.</p>
11
12 #include <qptrcollection.h>
13
14 Inherited by QAsciiCache, QAsciiDict, QCache, QDict, QIntCache,
15 QIntDict, QPtrList, QPtrDict, and QPtrVector.
16
17 Public Members
18 bool autoDelete () const
19 void setAutoDelete ( bool enable )
20 virtual uint count () const = 0
21 virtual void clear () = 0
22 typedef void * Item
23
24 Protected Members
25 QPtrCollection ()
26 QPtrCollection ( const QPtrCollection & source )
27 virtual ~QPtrCollection ()
28 virtual Item newItem ( Item d )
29 virtual void deleteItem ( Item d ) = 0
30
32 The QPtrCollection class is the base class of most pointer-based Qt
33 collections.
34
35 The QPtrCollection class is an abstract base class for the Qt
36 collection classes QDict, QPtrList, etc. Qt also includes value based
37 collections, e.g. QValueList, QMap, etc.
38
39 A QPtrCollection only knows about the number of objects in the
40 collection and the deletion strategy (see setAutoDelete()).
41
42 A collection is implemented using the Item (generic collection item)
43 type, which is a void*. The template classes that create the real
44 collections cast the Item to the required type.
45
46 See also Collection Classes and Non-GUI Classes.
47
48 Member Type Documentation
50 This type is the generic "item" in a QPtrCollection.
51
54 Constructs a collection. The constructor is protected because
55 QPtrCollection is an abstract class.
56
58 Constructs a copy of source with autoDelete() set to FALSE. The
59 constructor is protected because QPtrCollection is an abstract class.
60
61 Note that if source has autoDelete turned on, copying it will risk
62 memory leaks, reading freed memory, or both.
63
65 Destroys the collection. The destructor is protected because
66 QPtrCollection is an abstract class.
67
69 Returns the setting of the auto-delete option. The default is FALSE.
70
71 See also setAutoDelete().
72
74 Removes all objects from the collection. The objects will be deleted if
75 auto-delete has been enabled.
76
77 See also setAutoDelete().
78
79 Reimplemented in QAsciiCache, QAsciiDict, QCache, QDict, QIntCache,
80 QIntDict, QPtrList, QPtrDict, and QPtrVector.
81
83 Returns the number of objects in the collection.
84
85 Reimplemented in QAsciiCache, QAsciiDict, QCache, QDict, QIntCache,
86 QIntDict, QPtrList, QPtrDict, and QPtrVector.
87
89 Reimplement this function if you want to be able to delete items.
90
91 Deletes an item that is about to be removed from the collection.
92
93 This function has to reimplemented in the collection template classes,
94 and should only delete item d if auto-delete has been enabled.
95
96 Warning: If you reimplement this function you must also reimplement the
97 destructor and call the virtual function clear() from your destructor.
98 This is due to the way virtual functions and destructors work in C++:
99 Virtual functions in derived classes cannot be called from a
100 destructor. If you do not do this, your deleteItem() function will not
101 be called when the container is destroyed.
102
103 See also newItem() and setAutoDelete().
104
106 Virtual function that creates a copy of an object that is about to be
107 inserted into the collection.
108
109 The default implementation returns the d pointer, i.e. no copy is made.
110
111 This function is seldom reimplemented in the collection template
112 classes. It is not common practice to make a copy of something that is
113 being inserted.
114
115 See also deleteItem().
116
118 Sets the collection to auto-delete its contents if enable is TRUE and
119 to never delete them if enable is FALSE.
120
121 If auto-deleting is turned on, all the items in a collection are
122 deleted when the collection itself is deleted. This is convenient if
123 the collection has the only pointer to the items.
124
125 The default setting is FALSE, for safety. If you turn it on, be careful
126 about copying the collection - you might find yourself with two
127 collections deleting the same items.
128
129 Note that the auto-delete setting may also affect other functions in
130 subclasses. For example, a subclass that has a remove() function will
131 remove the item from its data structure, and if auto-delete is enabled,
132 will also delete the item.
133
134 See also autoDelete().
135
136 Examples:
137
138
140 http://doc.trolltech.com/qptrcollection.html
141 http://www.trolltech.com/faq/tech.html
142
144 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
145 license file included in the distribution for a complete license
146 statement.
147
149 Generated automatically from the source code.
150
152 If you find a bug in Qt, please report it as described in
153 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
154 help you. Thank you.
155
156 The definitive Qt documentation is provided in HTML format; it is
157 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
158 web browser. This man page is provided as a convenience for those users
159 who prefer man pages, although this format is not officially supported
160 by Trolltech.
161
162 If you find errors in this manual page, please report them to qt-
163 bugs@trolltech.com. Please include the name of the manual page
164 (qptrcollection.3qt) and the Qt version (3.3.8).
165
166
167
168Trolltech AS 2 February 2007 QPtrCollection(3qt)