QHash数据是无序的!
QHash<int,QString> moneyHash;
moneyHash.insert(1,"一块钱");
moneyHash.insert(10,"十块钱");
moneyHash.insert(20,"二十块钱");
moneyHash[50] = "五十块钱";
moneyHash[100] = "一百块钱";
moneyHash.insertMulti(100,"毛爷爷");
//moneyHash[100] = "毛爷爷";
一个键对应多个值要用insertMulti?
QHashIterator<int,QString> it_mr(moneyHash);
qDebug()<<endl<<"只读正遍历人民币:";
for(it_mr.toFront();it_mr.hasNext();)
qDebug()<<it_mr.key()<<":"<<it_mr.next().value();
QMutableHashIterator<int,QString> it_mrw(moneyHash);
//修改数据
if(it_mrw.findNext("十块钱"))
it_mrw.setValue("10元");
qDebug()<<endl<<"更新10元后遍历:";
for(it_mrw.toFront();it_mrw.hasNext();)
qDebug()<<it_mrw.key()<<":"<<it_mrw.next().value();