const Key QMap::key ( const T & value ) const
返回对应值value的第一个key
如果map不包含项目,函数返回一个缺省的构建的key
函数是慢的(线性时间),因为QMap的内部数据结构是最佳的为快速查找b通过key,而不是通过value
const Key QMap::key ( const T & value, const Key & defaultKey ) const
QList<Key> QMap::keys () const
QList<Key> QMap::keys ( const T & value ) const
iterator QMap::lowerBound ( const Key & key )
返回一个迭代器指向key对应的第一个项目。如果map不包含key对应项目,函数返回一个迭代器到一个最近的较大的key对应的项目。
QMap<int, QString> map;
map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.lowerBound(0);
map.lowerBound(1);
map.lowerBound(2);
map.lowerBound(10);
map.lowerBound(999);
如果map包含多重项目,这个函数返回一个迭代器,指向最近的值。另一个值是可进入的通过增加迭代器。例如,这是一些代码,迭代相同key的所有项目:
QMap<QString, int> map;
...
QMap<QString, int>::const_iterator i = map.lowerBound("HDR");
QMap<QString, int>::const_iterator upperBound = map.upperBound("HDR");
while (i != upperBound) {
cout << i.value() << endl;
++i;
}
const_iterator QMap::lowerBound ( const Key & key ) const
int QMap::remove ( const Key & key )
int QMap::size () const
T QMap::take ( const Key & key )
移除key对应的项目,返回对应的值。如果项目不存在于map,函数简单的返回一个缺省构造的值。如果一个key对应多个项目,只是最近的插入的一个被移除并返回。
如果你不使用返回值,remove()是更有效率的。
std::map<Key, T> QMap::toStdMap () const
然会一个stl map等同于这个QMap
QList<Key> QMap::uniqueKeys () const
返回一个清单,包含所有的key在升序。在map发生多次的keys在返回清单中只发生一次。
QMap<Key, T> & QMap::unite ( const QMap<Key, T> & other )
插入其他map中所有的项目到这个map。如果一个key是普遍的maps,结果map将包含key多次。
iterator QMap::upperBound ( const Key & key )
返回一个迭代器指向立即跟着最后一个项目的项目。如果map不包含key对应的项目,函数返回一个迭代器到最近一个较大的key的项目。
QMap<int, QString> map;
map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.upperBound(0);
map.upperBound(1);
map.upperBound(2);
map.upperBound(10);
map.upperBound(999);
const_iterator QMap::upperBound ( const Key & key ) const
const T QMap::value ( const Key & key ) const
const T QMap::value ( const Key & key, const T & defaultValue ) const
QList<T> QMap::values () const
QList<T> QMap::values ( const Key & key ) const
bool QMap::operator!= ( const QMap<Key, T> & other ) const
QMap<Key, T> & QMap::operator= ( const QMap<Key, T> & other )
bool QMap::operator== ( const QMap<Key, T> & other ) const
T & QMap::operator[] ( const Key & key )
const T QMap::operator[] ( const Key & key ) const
相关非成员:
写map到流out中。
读一个map从流in到map