[Interest] initialising a dictionary-type container instance with a static table?

René J.V. Bertin rjvbertin at gmail.com
Mon Jan 2 15:02:13 CET 2017

On Monday January 2 2017 14:36:03 Konstantin Shegunov wrote:

>Do you mean something like this?
>It isn't exactly pretty but should work okay.

Yes and no. Behind the scenes the code would of course look much like that, but in user code I was thinking along the lines of

QMap<MyEnum,QString> dict = { {Enum1, QStringLiteral("Enum1")}, {Enum2, QStringLiteral("Enum2")} };

I considered what you suggested, of course. Writing such a generic interface makes sense if you can reuse it sufficiently often (or if you have really many entries to add), but rarely if you have just a few small dicts to create here and there.


More information about the Interest mailing list