PDA

View Full Version : Remove Item from QMultiHash



anbu01
9th December 2014, 06:01
Hi,
How do we remove all value of particular key in QMultiHash.
thanks,

jefftee
9th December 2014, 06:19
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?

anbu01
9th December 2014, 06:49
@ 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.
10794

anda_skoa
9th December 2014, 07:10
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,
_

anbu01
9th December 2014, 07:31
@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.

jefftee
9th December 2014, 08:09
I am not sure why code completion shows QMultiHash::remove() (http://qt-project.org/doc/qt-5/qmultihash.html#remove-2) 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???

anbu01
9th December 2014, 08:22
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........