Results 1 to 7 of 7

Thread: Remove Item from QMultiHash

  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Remove Item from QMultiHash

    Hi,
    How do we remove all value of particular key in QMultiHash.
    thanks,

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Remove Item from QMultiHash

    The doc says QMultiHash::remove(const Key &key) will remove all of the items that match the key. QMultiHash::remove(const Key &key, const T &value) will remove a specific key/value pair.

    Have you tried that method?

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove Item from QMultiHash

    @ jthomps:Thanks for your reply but remove doesnt shows me as method.It shows as namespace am i missing something.Please see the image as it shows remove not as method so how can i use it.
    rmoveIssue.png

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove Item from QMultiHash

    If you look at the documentation, you will see that remove() is not a static method.
    Which is quite obvious, it needs some hash object to remove from.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove Item from QMultiHash

    @anda_skoa So you say the below code should show me remove() as method.

    QMultiHash<int,QString> myMultiHash;
    myMultiHash.remove(key);

    but still it doesn't show as method.Can you help on this.
    Last edited by anbu01; 9th December 2014 at 07:44.

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Remove Item from QMultiHash

    I am not sure why code completion shows QMultiHash::remove() as a namespace. The documentation says that QMultiHash::remove() method is an overloaded function from QHash::remove(). The QHash doc explains that remove() is used to remove all items matching the key, etc.

    I would recommend that as you begin to learn Qt, use the documentation as it is very complete and frequently shows examples. While I haven't noticed many issues with code completion icons that are displayed, I would use the doc as your primary learning method.

    So the big question is, have you tried it and does it work for you???

  7. The following user says thank you to jefftee for this useful post:

    anbu01 (9th December 2014)

  8. #7
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove Item from QMultiHash

    ooops....i don't know whom to blame(Qt creator or me) actually it shows namespace icon but it works as method. Thanks for the help guys.But is this a bug in Qt creator........

Similar Threads

  1. Remove last item with QStingList
    By pcoliver in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2012, 11:45
  2. Remove an item
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 16th September 2009, 07:47
  3. How to use QMap::remove() to delete some item?
    By jedychen in forum Qt Programming
    Replies: 5
    Last Post: 18th September 2008, 07:29
  4. QListWidgetItem remove an item
    By mattia in forum Newbie
    Replies: 4
    Last Post: 9th November 2007, 07:57
  5. remove item from QListWidget
    By yushinee in forum Newbie
    Replies: 3
    Last Post: 2nd October 2007, 20:40

Tags for this Thread

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.