> Sent: Wednesday, June 09, 2021 at 10:48 AM
> From: "Thiago Macieira" <thiago.macie...@intel.com>
> To: interest@qt-project.org
> Subject: Re: [Interest] QJsonDocument::fromVariant failing with list
>
> On Wednesday, 9 June 2021 07:28:08 PDT Jason H wrote:
> > One hack I would workfor me is a new class, QVariantMapList, (List of
> > QVariantMaps) which is really all I need at the moment, unless there'd be a
> > need for QVariantListList too? (That's a terrible name though)
> >
> > Ultimately, I just want to express JSON as closely as I can in C++.
> > Ideally:
> > QVariantMap map {
> > {"err", QVariant()},
> > {"letters", QVariantMapList {
> > {{"a",1}},
> > {{"b",2}},
> > {{"c",3}}
> > }}
> > };
>
> Stop using QVariantMapList. You want a QVariantMap.

I think you meant QVariantList?:
 QVariantMap map {
   {"err", QVariant()},
   {"letters", QVariantList {
     QVariantMap {{"a",1}},
     QVariantMap {{"b",2}},
     QVariantMap {{"c",3}}
   }}
 };

I had hoped that by using QList<QVariantMap> that I could omit the 3 
QVariantMaps above.

If you didn't mean QVariantList, then I have confused you, what I wanted was
(JSON) [{"a":1}, {"b":2}, {"c":3}] not {"a":1, "b":2, "c":3}
Perhaps I confused you by using sequential letters but [{"a":1}, {"a":2}, 
{"a":3}] could be just as valid.

But anyway, it seems my mistake was thinking that QVariant hold a 
QList<QVariantMap>, the best thing possible is the more general case of 
QVariantList, and this can be a heterogeneous collection of QVariants. Neither 
compiler nor Qt is capable of enforcing homogeneity as a QList of QVariantMaps 
AND having that collection being a QVariant itself, in a declaration. It would 
have to be built at runtime.

Did I get that right?




_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to