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