Results 1 to 2 of 2

Thread: How to modify QHash values?

  1. #1
    Join Date
    Nov 2008
    Posts
    23
    Thanks
    2

    Default How to modify QHash values?

    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.

    Qt Code:
    1. if(hash.contains(s_ip))
    2. {
    3. QList<Packet*> pkt = hash.values();
    4. QListIterator<Packet*> i(pkt);
    5. while (i.hasNext()){
    6. Packet *temp = i.next();
    7.  
    8. temp->setLength(len);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to modify QHash values?

    Qt Code:
    1. hash["key"] = *pointerToYourClassPacketObject;
    To copy to clipboard, switch view to plain text mode 

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

  3. The following user says thank you to Lykurg for this useful post:

    darshan (19th February 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.