<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-CA" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Most likely the QJson doesn’t known what to do with your QList<> type object. You should put those object into a QVariantList, right now you have a QVariantList that contain a QList as first element. You should convert the Qlist to a QVariant
 (not sure you want 2 level deep array, but right now you do). You QList<QVariantMap> and QVariantList is QList<QVariant>.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Right now if it could do something with the QList you would get this:<o:p></o:p></p>
<p class="MsoNormal">{"err":null,"letters":[[{"a": 1},{"b": 2},{"c": 3}]]}<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Something like this, not sure this is possible declaration but you are looking to get this in the end. Or make a converter that convert your QList to a QVariantList if you still need that QList absolutely.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">QVariantList letters {<br>
                        QVariantMap {{"a",1}},<br>
                        QVariantMap {{"b",2}},<br>
                        QVariantMap {{"c",3}}<br>
        };<span lang="FR-CA" style="color:white"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA"><o:p> </o:p></span></p>
<p class="MsoNormal">Not tested just giving the idea<o:p></o:p></p>
<p class="MsoNormal">// can use traits if T is QVariant to simply convert by casting since it’s the same<o:p></o:p></p>
<p class="MsoNormal"><span lang="FR-CA">Template<typename T><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">QVariantList Convert<T>(const QList<T>& l)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">                QVariantList rv;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">                Rv.reserve(l.size());<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">                </span>for(auto i in l)<o:p></o:p></p>
<p class="MsoNormal">                {<o:p></o:p></p>
<p class="MsoNormal">                                rv.append(QVariant::fromValue(i));<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:36.0pt">}<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:36.0pt">return rv;<o:p></o:p></p>
<p class="MsoNormal"><span lang="FR-CA">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Interest <interest-bounces@qt-project.org> on behalf of Jason H <jhihn@gmx.com><br>
<b>Date: </b>Tuesday, June 8, 2021 at 4:23 PM<br>
<b>To: </b>interestqt-project.org <interest@qt-project.org><br>
<b>Subject: </b>[Interest] QJsonDocument::fromVariant failing with list<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal">I'm having trouble with QJsonDocument::fromVariant() is not handling arrays:<br>
<br>
        QVariant list;<br>
<br>
        QList<QVariantMap> letters {<br>
                        QVariantMap {{"a",1}},<br>
                        QVariantMap {{"b",2}},<br>
                        QVariantMap {{"c",3}}<br>
        };<br>
<br>
        list.setValue(letters);<br>
        map["err"] = QVariant(); // null<br>
        map["letters"] = list;<br>
<br>
        qDebug() << QJsonDocument::fromVariant(map)<br>
                                .toJson(QJsonDocument::Compact);<br>
<br>
Output:<br>
{"err":null,"letters":null}<br>
<br>
I'm expecting:<br>
{"err":null,"letters":[{"a": 1},{"b": 2},{"c": 3}]}<br>
<br>
The debugger (screenshot attached) sees it. Is this a bug or am I doing it wrong?<o:p></o:p></p>
</div>
</div>
</body>
</html>