Hello Qt Forum :D
I recently researched about QMap a bit and I have a question.
Is it possible to make a QMap ( or any other container ) that you can assign multiple values per key?
for example:
Code:
QMap<QString, int, int, double>
Printable View
Hello Qt Forum :D
I recently researched about QMap a bit and I have a question.
Is it possible to make a QMap ( or any other container ) that you can assign multiple values per key?
for example:
Code:
QMap<QString, int, int, double>
I already had a look at it, but it seemed the only difference is it doesn't overwrite existing keys with the same name?
This difference is enough to suit your needs. An alternative is this:
This is a better equivalent to the code from your post but less practical in my opinion.
Thanks Wysota,
but how would I set their values?
not like insert(mymap, SomeStruct) .
Because then the variables wouldn't be initialized right?
Uninitialized variables is not a problem as you can have constructors for your stuct but it might be a good idea to provide a method for the map that allows to set each value of the struct separately. But I think the solution with multimap is better in most cases as the only "trick" you need to do there is to convert QVariant to proper types when retrieving data from the map.