⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdict.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QDict 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQDict \- Template class that provides a dictionary based on QString keys.PP\fC#include <qdict.h>\fR.PPInherits QPtrCollection..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQDict\fR ( int size = 17, bool caseSensitive = TRUE )".br.ti -1c.BI "\fBQDict\fR ( const QDict<type> & dict )".br.ti -1c.BI "\fB~QDict\fR ()".br.ti -1c.BI "QDict<type> & \fBoperator=\fR ( const QDict<type> & dict )".br.ti -1c.BI "virtual uint \fBcount\fR () const".br.ti -1c.BI "uint \fBsize\fR () const".br.ti -1c.BI "bool \fBisEmpty\fR () const".br.ti -1c.BI "void \fBinsert\fR ( const QString & key, const type * item )".br.ti -1c.BI "void \fBreplace\fR ( const QString & key, const type * item )".br.ti -1c.BI "bool \fBremove\fR ( const QString & key )".br.ti -1c.BI "type * \fBtake\fR ( const QString & key )".br.ti -1c.BI "type * \fBfind\fR ( const QString & key ) const".br.ti -1c.BI "type * \fBoperator[]\fR ( const QString & key ) const".br.ti -1c.BI "virtual void \fBclear\fR ()".br.ti -1c.BI "void \fBresize\fR ( uint newsize )".br.ti -1c.BI "void \fBstatistics\fR () const".br.in -1c.SS "Important Inherited Members".in +1c.ti -1c.BI "bool \fBautoDelete\fR () const".br.ti -1c.BI "void \fBsetAutoDelete\fR ( bool enable )".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual QDataStream & \fBread\fR ( QDataStream & s, QPtrCollection::Item & item )".br.ti -1c.BI "virtual QDataStream & \fBwrite\fR ( QDataStream & s, QPtrCollection::Item ) const".br.in -1c.SH DESCRIPTIONThe QDict class is a template class that provides a dictionary based on QString keys..PPQDict is implemented as a template class. Define a template instance QDict<X> to create a dictionary that operates on pointers to X (X*)..PPA dictionary is a collection of key-value pairs. The key is a QString used for insertion, removal and lookup. The value is a pointer. Dictionaries provide very fast insertion and lookup..PPIf you want to use non-Unicode, plain 8-bit \fCchar*\fR keys, use the QAsciiDict template. A QDict has the same performance as a QAsciiDict. If you want to have a dictionary that maps QStrings to QStrings use QMap..PPThe size() of the dictionary is very important. In order to get good performance, you should use a suitably large prime number. Suitable means equal to or larger than the maximum expected number of dictionary items. Size is set in the constructor but may be changed with resize()..PPItems are inserted with insert(), and removed with remove(). All the items in a dictionary can be removed with clear(). The number of items in the dictionary is returned by count(). If the dictionary contains no items isEmpty() returns TRUE. You can change an item's value with replace(). Items are looked up with operator[](), or with find() which return a pointer to the value or 0 if the given key does not exist. You can take an item out of the dictionary with take()..PPCalling setAutoDelete(TRUE) for a dictionary tells it to delete items that are removed. The default behaviour is not to delete items when they are removed..PPQDict is implemented by QGDict as a hash array with a fixed number of entries. Each array entry points to a singly linked list of buckets, in which the dictionary items are stored. When an item is inserted with a key, the key is converted (hashed) to an integer index into the hash array. The item is inserted before the first bucket in the list of buckets..PPLooking up an item is normally very fast. The key is again hashed to an array index. Then QDict scans the list of buckets and returns the item found or null if the item was not found. You cannot insert null pointers into a dictionary..PPItems with equal keys are allowed. When inserting two items with the same key, only the last inserted item will be visible (last in, first out) until it is removed..PPThe QDictIterator class can traverse the dictionary, but only in an arbitrary order. Multiple iterators may independently traverse the same dictionary..PPWhen inserting an item into a dictionary, only the pointer is copied, not the item itself, i.e. a shallow copy is made. It is possible to make the dictionary copy all of the item's data (a deep copy) when an item is inserted. insert() calls the virtual function QPtrCollection::newItem() for the item to be inserted. Inherit a dictionary and reimplement it if you want deep copies..PPWhen removing a dictionary item, the virtual function QPtrCollection::deleteItem() is called. QDict's default implementation is to delete the item if auto-deletion is enabled..PPExample #1:.PP.nf.br    QDict<QLineEdit> fields;.br    fields.insert( "forename", new QLineEdit( this ) );.br    fields.insert( "surname", new QLineEdit( this ) );.br.br    fields["forename"]->setText( "Homer" );.br    fields["surname"]->setText( "Simpson" );.br.br    QDictIterator<char> it( extra ); // See QDictIterator.br    for( ; it.current(); ++it ).br        cout << it.currentKey() << ": " << it.current()->text() << endl;.br    cout << endl;.br.br    if ( fields["forename"] && fields["surname"] ).br        cout << fields["forename"]->text() << " ".br.br            << fields["surname"]->text() << endl;  // Prints "Homer Simpson".br.br    fields.remove( "forename" ); // Does not delete the line edit.br    if ( ! fields["forename"] ).br        cout << "forename is not in the dictionary" << endl;.br.fiIn this example we use a dictionary to keep track of the line edits we're using. We insert each line edit into the dictionary with a unique name and then access the line edits via the dictionary..PPExample #2:.PP.nf.br    QStringList styleList = QStyleFactory::styles();.br    styleList.sort();.br    QDict<int> letterDict( 17, FALSE );.br    for ( QStringList::Iterator it = styleList.begin(); it != styleList.end(); ++it ) {.br        QString styleName = *it;.br        QString styleAccel = styleName;.br        if ( letterDict[styleAccel.left(1)] ) {.br            for ( uint i = 0; i < styleAccel.length(); i++ ) {.br                if ( ! letterDict[styleAccel.mid( i, 1 )] ) {.br                    styleAccel = styleAccel.insert( i, '&' );.br                    letterDict.insert(styleAccel.mid( i, 1 ), (const int *)1);.br                    break;.br                }.br            }.br        } else {.br

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -