| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | 
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/qdict.doc:41 --> | 
|---|
| 3 | <html> | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
| 6 | <title>QDict Class</title> | 
|---|
| 7 | <style type="text/css"><!-- | 
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; } | 
|---|
| 9 | a:link { color: #004faf; text-decoration: none } | 
|---|
| 10 | a:visited { color: #672967; text-decoration: none } | 
|---|
| 11 | body { background: #ffffff; color: black; } | 
|---|
| 12 | --></style> | 
|---|
| 13 | </head> | 
|---|
| 14 | <body> | 
|---|
| 15 |  | 
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> | 
|---|
| 17 | <tr bgcolor="#E5E5E5"> | 
|---|
| 18 | <td valign=center> | 
|---|
| 19 | <a href="index.html"> | 
|---|
| 20 | <font color="#004faf">Home</font></a> | 
|---|
| 21 | | <a href="classes.html"> | 
|---|
| 22 | <font color="#004faf">All Classes</font></a> | 
|---|
| 23 | | <a href="mainclasses.html"> | 
|---|
| 24 | <font color="#004faf">Main Classes</font></a> | 
|---|
| 25 | | <a href="annotated.html"> | 
|---|
| 26 | <font color="#004faf">Annotated</font></a> | 
|---|
| 27 | | <a href="groups.html"> | 
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a> | 
|---|
| 29 | | <a href="functions.html"> | 
|---|
| 30 | <font color="#004faf">Functions</font></a> | 
|---|
| 31 | </td> | 
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QDict Class Reference</h1> | 
|---|
| 33 |  | 
|---|
| 34 | <p>The QDict class is a template class that provides a | 
|---|
| 35 | dictionary based on QString keys. | 
|---|
| 36 | <a href="#details">More...</a> | 
|---|
| 37 | <p><tt>#include <<a href="qdict-h.html">qdict.h</a>></tt> | 
|---|
| 38 | <p>Inherits <a href="qptrcollection.html">QPtrCollection</a>. | 
|---|
| 39 | <p><a href="qdict-members.html">List of all member functions.</a> | 
|---|
| 40 | <h2>Public Members</h2> | 
|---|
| 41 | <ul> | 
|---|
| 42 | <li class=fn><a href="#QDict"><b>QDict</b></a> ( int size = 17, bool caseSensitive = TRUE )</li> | 
|---|
| 43 | <li class=fn><a href="#QDict-2"><b>QDict</b></a> ( const QDict<type> & dict )</li> | 
|---|
| 44 | <li class=fn><a href="#~QDict"><b>~QDict</b></a> ()</li> | 
|---|
| 45 | <li class=fn>QDict<type> & <a href="#operator-eq"><b>operator=</b></a> ( const QDict<type> & dict )</li> | 
|---|
| 46 | <li class=fn>virtual uint <a href="#count"><b>count</b></a> () const</li> | 
|---|
| 47 | <li class=fn>uint <a href="#size"><b>size</b></a> () const</li> | 
|---|
| 48 | <li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li> | 
|---|
| 49 | <li class=fn>void <a href="#insert"><b>insert</b></a> ( const QString & key, const type * item )</li> | 
|---|
| 50 | <li class=fn>void <a href="#replace"><b>replace</b></a> ( const QString & key, const type * item )</li> | 
|---|
| 51 | <li class=fn>bool <a href="#remove"><b>remove</b></a> ( const QString & key )</li> | 
|---|
| 52 | <li class=fn>type * <a href="#take"><b>take</b></a> ( const QString & key )</li> | 
|---|
| 53 | <li class=fn>type * <a href="#find"><b>find</b></a> ( const QString & key ) const</li> | 
|---|
| 54 | <li class=fn>type * <a href="#operator[]"><b>operator[]</b></a> ( const QString & key ) const</li> | 
|---|
| 55 | <li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li> | 
|---|
| 56 | <li class=fn>void <a href="#resize"><b>resize</b></a> ( uint newsize )</li> | 
|---|
| 57 | <li class=fn>void <a href="#statistics"><b>statistics</b></a> () const</li> | 
|---|
| 58 | </ul> | 
|---|
| 59 | <h2>Important Inherited Members</h2> | 
|---|
| 60 | <ul> | 
|---|
| 61 | <li class=fn>bool <a href="#autoDelete"><b>autoDelete</b></a> () const</li> | 
|---|
| 62 | <li class=fn>void <a href="#setAutoDelete"><b>setAutoDelete</b></a> ( bool enable )</li> | 
|---|
| 63 | </ul> | 
|---|
| 64 | <h2>Protected Members</h2> | 
|---|
| 65 | <ul> | 
|---|
| 66 | <li class=fn>virtual QDataStream & <a href="#read"><b>read</b></a> ( QDataStream & s, QPtrCollection::Item & item )</li> | 
|---|
| 67 | <li class=fn>virtual QDataStream & <a href="#write"><b>write</b></a> ( QDataStream & s, QPtrCollection::Item ) const</li> | 
|---|
| 68 | </ul> | 
|---|
| 69 | <hr><a name="details"></a><h2>Detailed Description</h2> | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 | The QDict class is a template class that provides a | 
|---|
| 73 | dictionary based on <a href="qstring.html">QString</a> keys. | 
|---|
| 74 | <p> | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 | <p> | 
|---|
| 78 | <p> <a href="qmap.html">QMap</a> is an STL-compatible alternative to this class. | 
|---|
| 79 | <p> QDict is implemented as a template class. Define a template | 
|---|
| 80 | instance QDict<X> to create a dictionary that operates on | 
|---|
| 81 | pointers to X (X *). | 
|---|
| 82 | <p> A dictionary is a collection of key-value pairs. The key is a | 
|---|
| 83 | QString used for insertion, removal and lookup. The value is a | 
|---|
| 84 | pointer. Dictionaries provide very fast insertion and lookup. | 
|---|
| 85 | <p> If you want to use non-Unicode, plain 8-bit <tt>char*</tt> keys, use the | 
|---|
| 86 | <a href="qasciidict.html">QAsciiDict</a> template. A QDict has the same performance as a | 
|---|
| 87 | QAsciiDict. If you want to have a dictionary that maps QStrings to | 
|---|
| 88 | QStrings use QMap. | 
|---|
| 89 | <p> The <a href="#size">size</a>() of the dictionary is very important. In order to get | 
|---|
| 90 | good performance, you should use a suitably large <a href="primes.html#prime">prime</a> number. | 
|---|
| 91 | Suitable means equal to or larger than the maximum expected number | 
|---|
| 92 | of dictionary items. Size is set in the constructor but may be | 
|---|
| 93 | changed with <a href="#resize">resize</a>(). | 
|---|
| 94 | <p> Items are inserted with <a href="#insert">insert</a>(); 0 pointers cannot be inserted. | 
|---|
| 95 | Items are removed with <a href="#remove">remove</a>(). All the items in a dictionary can | 
|---|
| 96 | be removed with <a href="#clear">clear</a>(). The number of items in the dictionary is | 
|---|
| 97 | returned by <a href="#count">count</a>(). If the dictionary contains no items <a href="#isEmpty">isEmpty</a>() | 
|---|
| 98 | returns TRUE. You can change an item's value with <a href="#replace">replace</a>(). Items | 
|---|
| 99 | are looked up with <a href="#operator[]">operator[]</a>(), or with <a href="#find">find</a>() which return a | 
|---|
| 100 | pointer to the value or 0 if the given key does not exist. You can | 
|---|
| 101 | take an item out of the dictionary with <a href="#take">take</a>(). | 
|---|
| 102 | <p> Calling <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(TRUE) for a dictionary tells it to delete | 
|---|
| 103 | items that are removed. The default behaviour is not to delete | 
|---|
| 104 | items when they are removed. | 
|---|
| 105 | <p> When an item is inserted, the key is converted (hashed) to an | 
|---|
| 106 | integer index into an internal hash array. This makes lookup very | 
|---|
| 107 | fast. | 
|---|
| 108 | <p> Items with equal keys are allowed. When inserting two items with | 
|---|
| 109 | the same key, only the last inserted item will be accessible (last | 
|---|
| 110 | in, first out) until it is removed. | 
|---|
| 111 | <p> The <a href="qdictiterator.html">QDictIterator</a> class can traverse the dictionary, but only in | 
|---|
| 112 | an arbitrary order. Multiple iterators may independently traverse | 
|---|
| 113 | the same dictionary. | 
|---|
| 114 | <p> When inserting an item into a dictionary, only the pointer is | 
|---|
| 115 | copied, not the item itself, i.e. a <a href="shclass.html#shallow-copy">shallow copy</a> is made. It is | 
|---|
| 116 | possible to make the dictionary copy all of the item's data (a | 
|---|
| 117 | <a href="shclass.html#deep-copy">deep copy</a>) when an item is inserted. <a href="#insert">insert</a>() calls the virtual | 
|---|
| 118 | function <a href="qptrcollection.html#newItem">QPtrCollection::newItem</a>() for the item to be inserted. | 
|---|
| 119 | Inherit a dictionary and reimplement <a href="qptrcollection.html#newItem">newItem</a>() if you want deep | 
|---|
| 120 | copies. | 
|---|
| 121 | <p> When removing a dictionary item, the virtual function | 
|---|
| 122 | <a href="qptrcollection.html#deleteItem">QPtrCollection::deleteItem</a>() is called. QDict's default | 
|---|
| 123 | implementation is to delete the item if auto-deletion is enabled. | 
|---|
| 124 | <p> Example #1: | 
|---|
| 125 | <pre> | 
|---|
| 126 | QDict<QLineEdit> fields; // QString keys, QLineEdit* values | 
|---|
| 127 | fields.<a href="#insert">insert</a>( "forename", new <a href="qlineedit.html">QLineEdit</a>( this ) ); | 
|---|
| 128 | fields.<a href="#insert">insert</a>( "surname", new <a href="qlineedit.html">QLineEdit</a>( this ) ); | 
|---|
| 129 |  | 
|---|
| 130 | fields["forename"]->setText( "Homer" ); | 
|---|
| 131 | fields["surname"]->setText( "Simpson" ); | 
|---|
| 132 |  | 
|---|
| 133 | <a href="qdictiterator.html">QDictIterator</a><QLineEdit> it( fields ); // See QDictIterator | 
|---|
| 134 | for( ; it.<a href="qdictiterator.html#current">current</a>(); ++it ) | 
|---|
| 135 | cout << it.<a href="qdictiterator.html#currentKey">currentKey</a>() << ": " << it.<a href="qdictiterator.html#current">current</a>()->text() << endl; | 
|---|
| 136 | cout << endl; | 
|---|
| 137 |  | 
|---|
| 138 | if ( fields["forename"] && fields["surname"] ) | 
|---|
| 139 | cout << fields["forename"]->text() << " " | 
|---|
| 140 | << fields["surname"]->text() << endl;  // Prints "Homer Simpson" | 
|---|
| 141 |  | 
|---|
| 142 | fields.<a href="#remove">remove</a>( "forename" ); // Does not delete the line edit | 
|---|
| 143 | if ( ! fields["forename"] ) | 
|---|
| 144 | cout << "forename is not in the dictionary" << endl; | 
|---|
| 145 | </pre> | 
|---|
| 146 |  | 
|---|
| 147 | In this example we use a dictionary to keep track of the line | 
|---|
| 148 | edits we're using. We insert each line edit into the dictionary | 
|---|
| 149 | with a unique name and then access the line edits via the | 
|---|
| 150 | dictionary. | 
|---|
| 151 | <p> Example #2: | 
|---|
| 152 | <pre> | 
|---|
| 153 | <a href="qstringlist.html">QStringList</a> styleList = QStyleFactory::styles(); | 
|---|
| 154 | styleList.<a href="qstringlist.html#sort">sort</a>(); | 
|---|
| 155 | QDict<int> letterDict( 17, FALSE ); | 
|---|
| 156 | for ( QStringList::Iterator it = styleList.<a href="qvaluelist.html#begin">begin</a>(); it != styleList.<a href="qvaluelist.html#end">end</a>(); ++it ) { | 
|---|
| 157 | <a href="qstring.html">QString</a> styleName = *it; | 
|---|
| 158 | <a href="qstring.html">QString</a> styleAccel = styleName; | 
|---|
| 159 | if ( letterDict[styleAccel.<a href="qstring.html#left">left</a>(1)] ) { | 
|---|
| 160 | for ( uint i = 0; i < styleAccel.<a href="qstring.html#length">length</a>(); i++ ) { | 
|---|
| 161 | if ( ! letterDict[styleAccel.<a href="qstring.html#mid">mid</a>( i, 1 )] ) { | 
|---|
| 162 | styleAccel = styleAccel.<a href="qstring.html#insert">insert</a>( i, '&' ); | 
|---|
| 163 | letterDict.<a href="#insert">insert</a>(styleAccel.<a href="qstring.html#mid">mid</a>( i, 1 ), (const int *)1); | 
|---|
| 164 | break; | 
|---|
| 165 | } | 
|---|
| 166 | } | 
|---|
| 167 | } else { | 
|---|
| 168 | styleAccel = "&" + styleAccel; | 
|---|
| 169 | letterDict.<a href="#insert">insert</a>(styleAccel.<a href="qstring.html#left">left</a>(1), (const int *)1); | 
|---|
| 170 | } | 
|---|
| 171 | (void) new <a href="qaction.html">QAction</a>( styleName, QIconSet(), styleAccel, parent ); | 
|---|
| 172 | } | 
|---|
| 173 | </pre> | 
|---|
| 174 |  | 
|---|
| 175 | In the example we are using the dictionary to provide fast random | 
|---|
| 176 | access to the keys, and we don't care what the values are. The | 
|---|
| 177 | example is used to generate a menu of QStyles, each with a unique | 
|---|
| 178 | accelerator key (or no accelerator if there are no unused letters | 
|---|
| 179 | left). | 
|---|
| 180 | <p> We first obtain the list of available styles, then sort them so | 
|---|
| 181 | that the menu items will be ordered alphabetically. Next we create | 
|---|
| 182 | a dictionary of int pointers. The keys in the dictionary are each | 
|---|
| 183 | one character long, representing letters that have been used for | 
|---|
| 184 | accelerators. We iterate through our list of style names. If the | 
|---|
| 185 | first letter of the style name is in the dictionary, i.e. has been | 
|---|
| 186 | used, we iterate over all the characters in the style name to see | 
|---|
| 187 | if we can find a letter that hasn't been used. If we find an | 
|---|
| 188 | unused letter we put the accelerator ampersand (&) in front of it | 
|---|
| 189 | and add that letter to the dictionary. If we can't find an unused | 
|---|
| 190 | letter the style will simply have no accelerator. If the first | 
|---|
| 191 | letter of the style name is not in the dictionary we use it for | 
|---|
| 192 | the accelerator and add it to the dictionary. Finally we create a | 
|---|
| 193 | <a href="qaction.html">QAction</a> for each style. | 
|---|
| 194 | <p> <p>See also <a href="qdictiterator.html">QDictIterator</a>, <a href="qasciidict.html">QAsciiDict</a>, <a href="qintdict.html">QIntDict</a>, <a href="qptrdict.html">QPtrDict</a>, <a href="collection.html">Collection Classes</a>, and <a href="tools.html">Non-GUI Classes</a>. | 
|---|
| 195 |  | 
|---|
| 196 | <hr><h2>Member Function Documentation</h2> | 
|---|
| 197 | <h3 class=fn><a name="QDict"></a>QDict::QDict ( int size = 17, bool caseSensitive = TRUE ) | 
|---|
| 198 | </h3> | 
|---|
| 199 |  | 
|---|
| 200 | <p> Constructs a dictionary optimized for less than <em>size</em> entries. | 
|---|
| 201 | <p> We recommend setting <em>size</em> to a suitably large <a href="primes.html#prime">prime</a> number | 
|---|
| 202 | (e.g. a prime that's slightly larger than the expected number of | 
|---|
| 203 | entries). This makes the hash distribution better which will lead | 
|---|
| 204 | to faster lookup. | 
|---|
| 205 | <p> If <em>caseSensitive</em> is TRUE (the default), keys which differ only | 
|---|
| 206 | by case are considered different. | 
|---|
| 207 |  | 
|---|
| 208 | <h3 class=fn><a name="QDict-2"></a>QDict::QDict ( const <a href="qdict.html">QDict</a><type> & dict ) | 
|---|
| 209 | </h3> | 
|---|
| 210 |  | 
|---|
| 211 | <p> Constructs a copy of <em>dict</em>. | 
|---|
| 212 | <p> Each item in <em>dict</em> is inserted into this dictionary. Only the | 
|---|
| 213 | pointers are copied (shallow copy). | 
|---|
| 214 |  | 
|---|
| 215 | <h3 class=fn><a name="~QDict"></a>QDict::~QDict () | 
|---|
| 216 | </h3> | 
|---|
| 217 |  | 
|---|
| 218 | <p> Removes all items from the dictionary and destroys it. If | 
|---|
| 219 | <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>() is TRUE, each value is deleted. All iterators that | 
|---|
| 220 | access this dictionary will be reset. | 
|---|
| 221 | <p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). | 
|---|
| 222 |  | 
|---|
| 223 | <h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const | 
|---|
| 224 | </h3> | 
|---|
| 225 |  | 
|---|
| 226 | <p> Returns the setting of the auto-delete option. The default is FALSE. | 
|---|
| 227 | <p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). | 
|---|
| 228 |  | 
|---|
| 229 | <h3 class=fn>void <a name="clear"></a>QDict::clear ()<tt> [virtual]</tt> | 
|---|
| 230 | </h3> | 
|---|
| 231 |  | 
|---|
| 232 | <p> Removes all items from the dictionary. | 
|---|
| 233 | <p> The removed items are deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled. | 
|---|
| 234 | <p> All dictionary iterators that operate on the dictionary are reset. | 
|---|
| 235 | <p> <p>See also <a href="#remove">remove</a>(), <a href="#take">take</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). | 
|---|
| 236 |  | 
|---|
| 237 | <p>Reimplemented from <a href="qptrcollection.html#clear">QPtrCollection</a>. | 
|---|
| 238 | <h3 class=fn>uint <a name="count"></a>QDict::count () const<tt> [virtual]</tt> | 
|---|
| 239 | </h3> | 
|---|
| 240 |  | 
|---|
| 241 | <p> Returns the number of items in the dictionary. | 
|---|
| 242 | <p> <p>See also <a href="#isEmpty">isEmpty</a>(). | 
|---|
| 243 |  | 
|---|
| 244 | <p>Reimplemented from <a href="qptrcollection.html#count">QPtrCollection</a>. | 
|---|
| 245 | <h3 class=fn>type * <a name="find"></a>QDict::find ( const <a href="qstring.html">QString</a> & key ) const | 
|---|
| 246 | </h3> | 
|---|
| 247 |  | 
|---|
| 248 | <p> Returns the item with key <em>key</em>, or 0 if the key does not exist | 
|---|
| 249 | in the dictionary. | 
|---|
| 250 | <p> If there are two or more items with equal keys, then the most | 
|---|
| 251 | recently inserted item will be found. | 
|---|
| 252 | <p> Equivalent to the [] operator. | 
|---|
| 253 | <p> <p>See also <a href="#operator[]">operator[]</a>(). | 
|---|
| 254 |  | 
|---|
| 255 | <h3 class=fn>void <a name="insert"></a>QDict::insert ( const <a href="qstring.html">QString</a> & key, const type * item ) | 
|---|
| 256 | </h3> | 
|---|
| 257 |  | 
|---|
| 258 | <p> Inserts the key <em>key</em> with value <em>item</em> into the dictionary. | 
|---|
| 259 | <p> Multiple items can have the same key, in which case only the last | 
|---|
| 260 | item will be accessible using <a href="#operator[]">operator[]</a>(). | 
|---|
| 261 | <p> <em>item</em> may not be 0. | 
|---|
| 262 | <p> <p>See also <a href="#replace">replace</a>(). | 
|---|
| 263 |  | 
|---|
| 264 | <p>Example: <a href="themes-example.html#x326">themes/themes.cpp</a>. | 
|---|
| 265 | <h3 class=fn>bool <a name="isEmpty"></a>QDict::isEmpty () const | 
|---|
| 266 | </h3> | 
|---|
| 267 |  | 
|---|
| 268 | <p> Returns TRUE if the dictionary is empty, i.e. <a href="#count">count</a>() == 0; | 
|---|
| 269 | otherwise returns FALSE. | 
|---|
| 270 | <p> <p>See also <a href="#count">count</a>(). | 
|---|
| 271 |  | 
|---|
| 272 | <h3 class=fn><a href="qdict.html">QDict</a><type> & <a name="operator-eq"></a>QDict::operator= ( const <a href="qdict.html">QDict</a><type> & dict ) | 
|---|
| 273 | </h3> | 
|---|
| 274 |  | 
|---|
| 275 | <p> Assigns <em>dict</em> to this dictionary and returns a reference to this | 
|---|
| 276 | dictionary. | 
|---|
| 277 | <p> This dictionary is first cleared, then each item in <em>dict</em> is | 
|---|
| 278 | inserted into this dictionary. Only the pointers are copied | 
|---|
| 279 | (shallow copy), unless <a href="qptrcollection.html#newItem">newItem</a>() has been reimplemented. | 
|---|
| 280 |  | 
|---|
| 281 | <h3 class=fn>type * <a name="operator[]"></a>QDict::operator[] ( const <a href="qstring.html">QString</a> & key ) const | 
|---|
| 282 | </h3> | 
|---|
| 283 |  | 
|---|
| 284 | <p> Returns the item with key <em>key</em>, or 0 if the key does not | 
|---|
| 285 | exist in the dictionary. | 
|---|
| 286 | <p> If there are two or more items with equal keys, then the most | 
|---|
| 287 | recently inserted item will be found. | 
|---|
| 288 | <p> Equivalent to the <a href="#find">find</a>() function. | 
|---|
| 289 | <p> <p>See also <a href="#find">find</a>(). | 
|---|
| 290 |  | 
|---|
| 291 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="read"></a>QDict::read ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> & item )<tt> [virtual protected]</tt> | 
|---|
| 292 | </h3> | 
|---|
| 293 |  | 
|---|
| 294 | <p> Reads a dictionary item from the stream <em>s</em> and returns a | 
|---|
| 295 | reference to the stream. | 
|---|
| 296 | <p> The default implementation sets <em>item</em> to 0. | 
|---|
| 297 | <p> <p>See also <a href="#write">write</a>(). | 
|---|
| 298 |  | 
|---|
| 299 | <h3 class=fn>bool <a name="remove"></a>QDict::remove ( const <a href="qstring.html">QString</a> & key ) | 
|---|
| 300 | </h3> | 
|---|
| 301 |  | 
|---|
| 302 | <p> Removes the item with <em>key</em> from the dictionary. Returns TRUE if | 
|---|
| 303 | successful, i.e. if the item is in the dictionary; otherwise | 
|---|
| 304 | returns FALSE. | 
|---|
| 305 | <p> If there are two or more items with equal keys, then the last item | 
|---|
| 306 | that was inserted will be removed. | 
|---|
| 307 | <p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled. | 
|---|
| 308 | <p> All dictionary iterators that refer to the removed item will be | 
|---|
| 309 | set to point to the next item in the dictionary's traversal order. | 
|---|
| 310 | <p> <p>See also <a href="#take">take</a>(), <a href="#clear">clear</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). | 
|---|
| 311 |  | 
|---|
| 312 | <h3 class=fn>void <a name="replace"></a>QDict::replace ( const <a href="qstring.html">QString</a> & key, const type * item ) | 
|---|
| 313 | </h3> | 
|---|
| 314 |  | 
|---|
| 315 | <p> Replaces the value of the key, <em>key</em> with <em>item</em>. | 
|---|
| 316 | <p> If the item does not already exist, it will be inserted. | 
|---|
| 317 | <p> <em>item</em> may not be 0. | 
|---|
| 318 | <p> Equivalent to: | 
|---|
| 319 | <pre> | 
|---|
| 320 | QDict<char> dict; | 
|---|
| 321 | ... | 
|---|
| 322 | if ( dict.<a href="#find">find</a>( key ) ) | 
|---|
| 323 | dict.<a href="#remove">remove</a>( key ); | 
|---|
| 324 | dict.<a href="#insert">insert</a>( key, item ); | 
|---|
| 325 | </pre> | 
|---|
| 326 |  | 
|---|
| 327 | <p> If there are two or more items with equal keys, then the last item | 
|---|
| 328 | that was inserted will be replaced. | 
|---|
| 329 | <p> <p>See also <a href="#insert">insert</a>(). | 
|---|
| 330 |  | 
|---|
| 331 | <h3 class=fn>void <a name="resize"></a>QDict::resize ( uint newsize ) | 
|---|
| 332 | </h3> | 
|---|
| 333 |  | 
|---|
| 334 | <p> Changes the size of the hash table to <em>newsize</em>. The contents of | 
|---|
| 335 | the dictionary are preserved, but all iterators on the dictionary | 
|---|
| 336 | become invalid. | 
|---|
| 337 |  | 
|---|
| 338 | <h3 class=fn>void <a name="setAutoDelete"></a>QPtrCollection::setAutoDelete ( bool enable ) | 
|---|
| 339 | </h3> | 
|---|
| 340 |  | 
|---|
| 341 | <p> Sets the collection to auto-delete its contents if <em>enable</em> is | 
|---|
| 342 | TRUE and to never delete them if <em>enable</em> is FALSE. | 
|---|
| 343 | <p> If auto-deleting is turned on, all the items in a collection are | 
|---|
| 344 | deleted when the collection itself is deleted. This is convenient | 
|---|
| 345 | if the collection has the only pointer to the items. | 
|---|
| 346 | <p> The default setting is FALSE, for safety. If you turn it on, be | 
|---|
| 347 | careful about copying the collection - you might find yourself | 
|---|
| 348 | with two collections deleting the same items. | 
|---|
| 349 | <p> Note that the auto-delete setting may also affect other functions | 
|---|
| 350 | in subclasses. For example, a subclass that has a <a href="#remove">remove</a>() | 
|---|
| 351 | function will remove the item from its data structure, and if | 
|---|
| 352 | auto-delete is enabled, will also delete the item. | 
|---|
| 353 | <p> <p>See also <a href="qptrcollection.html#autoDelete">autoDelete</a>(). | 
|---|
| 354 |  | 
|---|
| 355 | <p>Examples: <a href="grapher-nsplugin-example.html#x2769">grapher/grapher.cpp</a>, <a href="scribble-example.html#x924">scribble/scribble.cpp</a>, and <a href="bigtable-example.html#x1291">table/bigtable/main.cpp</a>. | 
|---|
| 356 | <h3 class=fn>uint <a name="size"></a>QDict::size () const | 
|---|
| 357 | </h3> | 
|---|
| 358 |  | 
|---|
| 359 | <p> Returns the size of the internal hash array (as specified in the | 
|---|
| 360 | constructor). | 
|---|
| 361 | <p> <p>See also <a href="#count">count</a>(). | 
|---|
| 362 |  | 
|---|
| 363 | <h3 class=fn>void <a name="statistics"></a>QDict::statistics () const | 
|---|
| 364 | </h3> | 
|---|
| 365 |  | 
|---|
| 366 | <p> Debugging-only function that prints out the dictionary | 
|---|
| 367 | distribution using <a href="qapplication.html#qDebug">qDebug</a>(). | 
|---|
| 368 |  | 
|---|
| 369 | <h3 class=fn>type * <a name="take"></a>QDict::take ( const <a href="qstring.html">QString</a> & key ) | 
|---|
| 370 | </h3> | 
|---|
| 371 |  | 
|---|
| 372 | <p> Takes the item with <em>key</em> out of the dictionary without deleting | 
|---|
| 373 | it (even if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled). | 
|---|
| 374 | <p> If there are two or more items with equal keys, then the last item | 
|---|
| 375 | that was inserted will be taken. | 
|---|
| 376 | <p> Returns a pointer to the item taken out, or 0 if the key does not | 
|---|
| 377 | exist in the dictionary. | 
|---|
| 378 | <p> All dictionary iterators that refer to the taken item will be set | 
|---|
| 379 | to point to the next item in the dictionary traversal order. | 
|---|
| 380 | <p> <p>See also <a href="#remove">remove</a>(), <a href="#clear">clear</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). | 
|---|
| 381 |  | 
|---|
| 382 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="write"></a>QDict::write ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> ) const<tt> [virtual protected]</tt> | 
|---|
| 383 | </h3> | 
|---|
| 384 |  | 
|---|
| 385 | <p> Writes a dictionary item to the stream <em>s</em> and returns a | 
|---|
| 386 | reference to the stream. | 
|---|
| 387 | <p> <p>See also <a href="#read">read</a>(). | 
|---|
| 388 |  | 
|---|
| 389 | <!-- eof --> | 
|---|
| 390 | <hr><p> | 
|---|
| 391 | This file is part of the <a href="index.html">Qt toolkit</a>. | 
|---|
| 392 | Copyright © 1995-2007 | 
|---|
| 393 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center> | 
|---|
| 394 | <table width=100% cellspacing=0 border=0><tr> | 
|---|
| 395 | <td>Copyright © 2007 | 
|---|
| 396 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> | 
|---|
| 397 | <td align=right><div align=right>Qt 3.3.8</div> | 
|---|
| 398 | </table></div></address></body> | 
|---|
| 399 | </html> | 
|---|