[Interest] QJsonDocument::fromVariant failing with list

Jason H jhihn at gmx.com
Tue Jun 8 22:47:31 CEST 2021



> Sent: Tuesday, June 08, 2021 at 4:23 PM
> From: "Jason H" <jhihn at gmx.com>
> To: "interestqt-project.org" <interest at qt-project.org>
> Subject: [Interest] QJsonDocument::fromVariant failing with list
>
> I'm having trouble with QJsonDocument::fromVariant() is not handling arrays:
>
> 	QVariant list;
>
> 	QList<QVariantMap> letters {
> 			QVariantMap {{"a",1}},
> 			QVariantMap {{"b",2}},
> 			QVariantMap {{"c",3}}
> 	};
>
> 	list.setValue(letters);
> 	map["err"] = QVariant(); // null
> 	map["letters"] = list;
>
> 	qDebug() << QJsonDocument::fromVariant(map)
> 				.toJson(QJsonDocument::Compact);
>
> Output:
> {"err":null,"letters":null}
>
> I'm expecting:
> {"err":null,"letters":[{"a": 1},{"b": 2},{"c": 3}]}


So it looks like it works with:
QList<QVariant> letters {...}
It seems like QList<QVariantMap> vs QList<QVariant> should have the same behavior as each other?





More information about the Interest mailing list