[Interest] QJsonDocument::fromVariant failing with list

Jason H jhihn at gmx.com
Tue Jun 8 22:23:25 CEST 2021


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}]}

The debugger (screenshot attached) sees it. Is this a bug or am I doing it wrong?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2021-06-08 at 4.18.48 PM.png
Type: image/png
Size: 81186 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210608/4346980c/attachment-0001.png>


More information about the Interest mailing list