QMap与std::map相同,会自动根据key(第一项)进行升序排列html
返回结果:app
相关帮助文档请见官网函数
erase删除某项,因为map的key具备惟一性,能够经过m_map[XX]=YY;修改已有项的值,若此项并不存在则会建立新的。post
value若查找不到目标会返回默认值,对于默认值得解释:this
Returns a list containing all the values in the map, in ascending order of their keys. If a key is associated with multiple values, all of its values will be in the list, and not just the most recently inserted one.spa
若是没有主动设置默认值,返回Qt默认值,此值在文档的容器介绍有说明code
The documentation of certain container class functions refer to default-constructed values; for example, QVector automatically initializes its items with default-constructed values, and QMap::value() returns a default-constructed value if the specified key isn’t in the map. For most value types, this simply means that a value is created using the default constructor (e.g. an empty string for QString). But for primitive types like
int
anddouble
, as well as for pointer types, the C++ language doesn’t specify any initialization; in those cases, Qt’s containers automatically initialize the value to 0.htm
key方法若找不到相应key,一样返回默认值。ip
QMap使用Iterator.key(),和Iterator.value()方法获取第一个或第二个元素的值。ci
而std::map使用Iterator->first(), Iterator->second()来获取第一个或第二个元素的值
QMap实现了与std::map相互转换,toStdMap转到std,使用QMap的构造函数从std::map转到QMap