On segunda-feira, 2 de janeiro de 2017 13:02:12 BRST René J.V. Bertin wrote: > Hi, > > I must be overlooking or even forgetting something: is there a way to > initialise a QMap or QHash instance with a static table, say when you're > creating a fast lookup dictionary mapping enums or preprocessor tokens to a > QString? > > That's information known a compile time so I was expecting to be able to > avoid adding each mapping explicitly with a sequence of > > map[token] = "token"; > > statements. If that's indeed possible, the documentation doesn't really > showcase it.
The closest thing you have is the std::initializer_list constructor: static const QHash<Enum, QString> data = { { Value1, "Value1" }, { Value2, "Value2" } }; Note that all of this is constructed at *load* time, not at compile time and not on first use. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest