[Interest] QJsonDocument::fromVariant failing with list

Jérôme Godbout godboutj at amotus.ca
Wed Jun 9 16:15:37 CEST 2021


I understand the homogenous part when you do decoding, but encoding to json should support the homogenous, isn’t? why not? I understand that the decode of that json would alter the type.

QList<QVariantMap> • encode json • [{‘a’: ‘b’}, {‘c’:’d’}] • decode json • QList<QVariant>

Should be possible as long as QList<T> where T can be convert to QVariant. Maybe an external converter function should be used. If this is not supported, is there a way where we could trap this at compile time warning?

Maybe there is a limitation I do not see here.


From: Interest <interest-bounces at qt-project.org> on behalf of Thiago Macieira <thiago.macieira at intel.com>
Date: Wednesday, June 9, 2021 at 10:08 AM
To: interest at qt-project.org <interest at qt-project.org>
Subject: Re: [Interest] QJsonDocument::fromVariant failing with list
On Wednesday, 9 June 2021 00:34:40 PDT Allan Sandfeld Jensen wrote:
> > QList is not a type, it's a template. Neither QVariant nor QJsonDocument
> > can know all possible QList instantiations. So they have coded only a few
> > (QVariantList and QStringList only, possibly QVector<QVariant> and
> > QVector<QString> in Qt 5 too, I don't remember).
>
> I guess our system could detect QList<QVariant> as QVariantList and
> QList<QString> as QStringList. They should be binary identical anyway.

They already do.

The problem is QList of other things that it's not coded for, like
QList<QVariantMap> in this case, or QList<int> or QList<bool>. Since JSON
arrays are not expected to be homogeneous, QJsonDocument does not support
them.

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering



_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210609/4e7184e9/attachment.html>


More information about the Interest mailing list