PDA

View Full Version : How to modify QHash values?



darshan
19th February 2009, 12:33
Hello,

I would like to know how to modify a key associated with a value.

QHash<QString,Packet*> hash; Packet being my class object.

I have initially created the keys with empty objects. The hash consists of 5 items but i would like to modify the values for a particular key. I have tried the below but it sets the value for all keys.


if(hash.contains(s_ip))
{
QList<Packet*> pkt = hash.values();
QListIterator<Packet*> i(pkt);
while (i.hasNext()){
Packet *temp = i.next();

temp->setLength(len);

Lykurg
19th February 2009, 12:47
hash["key"] = *pointerToYourClassPacketObject;

If you have values (plural) associated with a key you need QMultiHash.