What should i use between QMap::insertMulti and QMultiMap to handle :
2 -> abc
2 -> def
3 -> ghi
3 -> jkl
What's the difference enter the 2 solutions ?
Both can serve this purpose. QMultiMap is actually a subclass of QMap.
If you are willing to have multiple values for single key, you can use: QMap : for inserting use insertMulti QMultiMap : for inserting use insert
If you are willing to have single value for single key, you can use: QMap : for inserting use insert QMultiMap : for inserting use replace
You can see that both can server both purpose. But, each have unique default behavior which matches its name. Also, each have some methods or operators which is convenient for single/multi.
It is better to choose type depending on your need. It is a good practice. For example, if you use QMap for storing single key multiple values, some other person who is going through your class members might get the impression that you are willing to save single key value pairs (from the data type) Similarly, if you use QMultiMap, anyone reading the definition can get the idea that the data will have multiple value for same key.
Reading Container Classes:
it looks like both can do the job. In this document there is also Algorithmic Complexity section where you can see that both classes have the same complexity.
I would choose
QMultiMap
just to better document the fact I'm going to hold multiple values with the same key.