[Interest] Storing QMaps in a QVariant

Alejandro Exojo aexojo at modpow.es
Mon Jan 13 11:45:24 CET 2014


2014/1/10 Alejandro Exojo <aexojo at modpow.es>:
> In Qt 5.2 I see Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE, where it
> even clarifies that "all of the Qt associative containers already have
> built-in support" and that if the key/value are already supported,
> QVariant should store everything. However, I'm not getting a
> QMap<quint8, quint16> inside a QVariant::fromValue.
>
> I've tried to use the different macros provided, and even add a call
> to qRegisterMetaType, just in case. I also tried a typedef. I think
> I'm missing something obvious, but I don't see what. Here is what I
> got:
>
> http://pastie.org/8620095
>
> Thank you.

I was indeed, missing something obvious: QVariant stored the values
just fine, it was the call to QSettings that was triggering warnings
at runtime about load() and save().

A simple call to
qRegisterMetaTypeStreamOperators<QMap<quint8,quint16>>(); made
QVariant save things in the configuration file and retrieving them
back.

-- 
Alejandro Exojo Piqueras

ModpoW, S.L.
Technova LaSalle | Sant Joan de la Salle 42 | 08022 Barcelona | www.modpow.es



More information about the Interest mailing list