📄 qdict.3qt
字号:
styleAccel = "&" + styleAccel;.br letterDict.insert(styleAccel.left(1), (const int *)1);.br }.br (void) new QAction( styleName, QIconSet(), styleAccel, parent );.br }.br.fiIn the example we are using the dictionary to provide fast random access to the keys, and we don't care what the values are. The example is used to generate a menu of QStyles, each with a unique accelerator key (or no accelerator if there are no unused letters left)..PPWe first obtain the list of available styles, then sort them so that the menu items will be ordered alphabetically. Next we create a dictionary of int pointers. The keys in the dictionary are each one character long, representing letters that have been used for accelerators. We iterate through our list of style names. If the first letter of the style name is in the dictionary, i.e. has been used, we iterate over all the characters in the style name to see if we can find a letter that hasn't been used. If we find an unused letter we put the accelerator ampersand (&) in front of it and add that letter to the dictionary. If we can't find an unused letter the style will simply have no accelerator. If the first letter of the style name is not in the dictionary we use it for the accelerator and add it to the dictionary. Finally we create a QAction for each style..PPSee also QDictIterator, QAsciiDict, QIntDict, QPtrDict, Collection Classes and Non-GUI Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QDict::QDict ( int size = 17, bool caseSensitive = TRUE )"Constructs a dictionary optimized for less than \fIsize\fR entries..PPWe recommend setting \fIsize\fR to a suitably large prime number (e.g. a prime that's slightly larger than the expected number of entries). This makes the hash distribution better which will lead to faster lookup..PPIf \fIcaseSensitive\fR is TRUE (the default), keys which differ only in case are considered different..SH "QDict::QDict ( const QDict<type> & dict )"Constructs a copy of \fIdict\fR..PPEach item in \fIdict\fR is inserted into this dictionary. Only the pointers are copied (shallow copy)..SH "QDict::~QDict ()"Removes all items from the dictionary and destroys it. If setAutoDelete() is TRUE each value is deleted. All iterators that access this dictionary will be reset..PPSee also setAutoDelete()..SH "bool QPtrCollection::autoDelete () const"Returns the setting of the auto-delete option. The default is FALSE..PPSee also setAutoDelete()..SH "void QDict::clear ()\fC [virtual]\fR"Removes all items from the dictionary..PPThe removed items are deleted if auto-deletion is enabled..PPAll dictionary iterators that operate on the dictionary are reset..PPSee also remove(), take() and setAutoDelete()..PPReimplemented from QPtrCollection..SH "uint QDict::count () const\fC [virtual]\fR"Returns the number of items in the dictionary..PPSee also isEmpty()..PPReimplemented from QPtrCollection..SH "type * QDict::find ( const QString & key ) const"Returns the item with key \fIkey\fR, or null if the key does not exist in the dictionary..PPIf there are two or more items with equal keys, then the last item that was inserted will be found..PPEquivalent to the [] operator..PPSee also operator[]()..SH "void QDict::insert ( const QString & key, const type * item )"Inserts the key \fIkey\fR with value \fIitem\fR into the dictionary..PPThe key does not have to be unique. If multiple items are inserted with the same key, only the last item will be visible..PPNull items are not allowed..PPSee also replace()..SH "bool QDict::isEmpty () const"Returns TRUE if the dictionary is empty, i.e. count() == 0; otherwise returns FALSE..PPSee also count()..SH "QDict<type> & QDict::operator= ( const QDict<type> & dict )"Assigns \fIdict\fR to this dictionary and returns a reference to this dictionary..PPThis dictionary is first cleared, then each item in \fIdict\fR is inserted into this dictionary. Only the pointers are copied (shallow copy), unless newItem() has been reimplemented()..SH "type * QDict::operator[] ( const QString & key ) const"Returns the item with key \fIkey\fR, or null if the key does not exist in the dictionary..PPIf there are two or more items with equal keys, then the last item that was inserted will be found..PPEquivalent to the find() function..PPSee also find()..SH "QDataStream & QDict::read ( QDataStream & s, QPtrCollection::Item & item )\fC [virtual protected]\fR"Reads a dictionary item from the stream \fIs\fR and returns a reference to the stream..PPThe default implementation sets \fIitem\fR to 0..PPSee also write()..SH "bool QDict::remove ( const QString & key )"Removes the item with \fIkey\fR from the dictionary. Returns TRUE if successful, or FALSE if the key does not exist in the dictionary..PPIf there are two or more items with equal keys, then the last item that was inserted will be removed..PPThe removed item is deleted if auto-deletion is enabled..PPAll dictionary iterators that refer to the removed item will be set to point to the next item in the dictionary traversing order..PPSee also take(), clear() and setAutoDelete()..SH "void QDict::replace ( const QString & key, const type * item )"Replaces the value of the key, \fIkey\fR with \fIitem\fR..PPIf the item does not already exist, it will be inserted..PPNull items are not allowed..PPEquivalent to:.PP.nf.br QDict<char> dict;.br ....br if ( dict.find( key ) ).br dict.remove( key );.br dict.insert( key, item );.br.fi.PPIf there are two or more items with equal keys, then the last item that was inserted will be replaced..PPSee also insert()..SH "void QDict::resize ( uint newsize )"Changes the size of the hashtable the \fInewsize\fR. The contents of the dictionary are preserved, but all iterators on the dictionary become invalid..SH "void QPtrCollection::setAutoDelete ( bool enable )"Sets the collection to auto-delete its contents if \fIenable\fR is TRUE and to never delete them if \fIenable\fR is FALSE..PPIf auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items..PPThe default setting is FALSE, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items..PPNote that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item..PPSee also autoDelete()..PPExamples:.)l grapher/grapher.cpp, scribble/scribble.cpp and table/bigtable/main.cpp..SH "uint QDict::size () const"Returns the size of the internal hash array (as specified in the constructor)..PPSee also count()..SH "void QDict::statistics () const"Debugging-only function that prints out the dictionary distribution using qDebug()..SH "type * QDict::take ( const QString & key )"Takes the item with \fIkey\fR out of the dictionary without deleting it (even if auto-deletion is enabled)..PPIf there are two or more items with equal keys, then the last item that was inserted will be taken..PPReturns a pointer to the item taken out, or null if the key does not exist in the dictionary..PPAll dictionary iterators that refer to the taken item will be set to point to the next item in the dictionary traversal order..PPSee also remove(), clear() and setAutoDelete()..SH "QDataStream & QDict::write ( QDataStream & s, QPtrCollection::Item ) const\fC [virtual protected]\fR"Writes a dictionary item to the stream \fIs\fR and returns a reference to the stream..PPSee also read()..SH "SEE ALSO".BR http://doc.trolltech.com/qdict.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf 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..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qdict.3qt) and the Qtversion (3.0.0).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -