📄 qmap.3qt
字号:
'\" t.TH QMap 3qt "9 December 2002" "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 NAMEQMap \- Value-based template class that provides a dictionary.SH SYNOPSIS\fC#include <qmap.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "typedef Key \fBkey_type\fR".br.ti -1c.BI "typedef T \fBmapped_type\fR".br.ti -1c.BI "typedef QPair<const key_type, mapped_type> \fBvalue_type\fR".br.ti -1c.BI "typedef value_type * \fBpointer\fR".br.ti -1c.BI "typedef const value_type * \fBconst_pointer\fR".br.ti -1c.BI "typedef value_type & \fBreference\fR".br.ti -1c.BI "typedef const value_type & \fBconst_reference\fR".br.ti -1c.BI "typedef size_t \fBsize_type\fR".br.ti -1c.BI "typedef QMapIterator<Key, T> \fBiterator\fR".br.ti -1c.BI "typedef QMapConstIterator<Key, T> \fBconst_iterator\fR".br.ti -1c.BI "typedef QPair<iterator, bool> \fBinsert_pair\fR".br.ti -1c.BI "typedef QMapIterator<Key, T> \fBIterator\fR".br.ti -1c.BI "typedef QMapConstIterator<Key, T> \fBConstIterator\fR".br.ti -1c.BI "typedef T \fBValueType\fR".br.ti -1c.BI "\fBQMap\fR ()".br.ti -1c.BI "\fBQMap\fR ( const QMap<Key, T> & m )".br.ti -1c.BI "\fBQMap\fR ( const std::map<Key, T> & m )".br.ti -1c.BI "\fB~QMap\fR ()".br.ti -1c.BI "QMap<Key, T> & \fBoperator=\fR ( const QMap<Key, T> & m )".br.ti -1c.BI "QMap<Key, T> & \fBoperator=\fR ( const std::map<Key, T> & m )".br.ti -1c.BI "iterator \fBbegin\fR ()".br.ti -1c.BI "iterator \fBend\fR ()".br.ti -1c.BI "const_iterator \fBbegin\fR () const".br.ti -1c.BI "const_iterator \fBend\fR () const".br.ti -1c.BI "iterator \fBreplace\fR ( const Key & k, const T & v )".br.ti -1c.BI "size_type \fBsize\fR () const".br.ti -1c.BI "bool \fBempty\fR () const".br.ti -1c.BI "QPair<iterator, bool> \fBinsert\fR ( const value_type & x )".br.ti -1c.BI "void \fBerase\fR ( iterator it )".br.ti -1c.BI "void \fBerase\fR ( const key_type & k )".br.ti -1c.BI "size_type \fBcount\fR ( const key_type & k ) const".br.ti -1c.BI "T & \fBoperator[]\fR ( const Key & k )".br.ti -1c.BI "void \fBclear\fR ()".br.ti -1c.BI "iterator \fBfind\fR ( const Key & k )".br.ti -1c.BI "const_iterator \fBfind\fR ( const Key & k ) const".br.ti -1c.BI "const T & \fBoperator[]\fR ( const Key & k ) const".br.ti -1c.BI "bool \fBcontains\fR ( const Key & k ) const".br.ti -1c.BI "size_type \fBcount\fR () const".br.ti -1c.BI "QValueList<Key> \fBkeys\fR () const".br.ti -1c.BI "QValueList<T> \fBvalues\fR () const".br.ti -1c.BI "bool \fBisEmpty\fR () const".br.ti -1c.BI "iterator \fBinsert\fR ( const Key & key, const T & value, bool overwrite = TRUE )".br.ti -1c.BI "void \fBremove\fR ( iterator it )".br.ti -1c.BI "void \fBremove\fR ( const Key & k )".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "void \fBdetach\fR ()".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QMap<Key, T> & m )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QMap<Key, T> & m )".br.in -1c.SH DESCRIPTIONThe QMap class is a value-based template class that provides a dictionary..PPQMap is a Qt implementation of an STL-like map container. It can be used in your application if the standard \fCmap\fR is not available on all your target platforms. QMap is part of the Qt Template Library..PPQMap<Key, Data> defines a template instance to create a dictionary with keys of type Key and values of type Data. QMap does not store pointers to the members of the map; instead, it holds a copy of every member. For this reason, QMap is value-based, whereas QPtrList and QDict are pointer-based..PPQMap contains and manages a collection of objects of type Data with associated key values of type Key and provides iterators that allow the contained objects to be addressed. QMap owns the contained items..PPSome classes cannot be used within a QMap. For example everything derived from QObject and thus all classes that implement widgets. Only values can be used in a QMap. To qualify as a value, the class must provide.TPA copy constructor.TPAn assignment operator.TPA default constructor, i.e. a constructor that does not take any arguments..PPNote that C++ defaults to field-by-field assignment operators and copy constructors if no explicit version is supplied. In many cases, this is sufficient..PPThe class used for the key requires that the \fCoperator<\fR is implemented to define ordering of the keys..PPQMap's function naming is consistent with the other Qt classes (e.g., count(), isEmpty()). QMap also provides extra functions for compatibility with STL algorithms, such as size() and empty(). Programmers already familiar with the STL \fCmap\fR can use these the STL-like functions if preferred..PPExample:.PP.nf.br #include <qstring.h>.br #include <qmap.h>.br #include <qstring.h>.br.br class Employee.br {.br public:.br Employee(): sn(0) {}.br Employee( const QString& forename, const QString& surname, int salary ).br : fn(forename), sn(surname), sal(salary).br { }.br.br QString forename() const { return fn; }.br QString surname() const { return sn; }.br int salary() const { return sal; }.br void setSalary( int salary ) { sal = salary; }.br.br private:.br QString fn;.br QString sn;.br int sal;.br };.br.br int main(int argc, char **argv).br {.br QApplication app( argc, argv );.br.br typedef QMap<QString, Employee> EmployeeMap;.br EmployeeMap map;.br.br map["JD001"] = Employee("John", "Doe", 50000);.br map["JW002"] = Employee("Jane", "Williams", 80000);.br map["TJ001"] = Employee("Tom", "Jones", 60000);.br.br Employee sasha( "Sasha", "Hind", 50000 );.br map["SH001"] = sasha;.br sasha.setSalary( 40000 );.br.br EmployeeMap::Iterator it;.br for ( it = map.begin(); it != map.end(); ++it ) {.br printf( "%s: %s, %s earns %d\\n",.br it.key().latin1(),.br it.data().surname().latin1(),.br it.data().forename().latin1(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -