[Interest] Can't JSON.stringify an object in QML

Jason H jhihn at gmx.com
Fri May 28 21:24:53 CEST 2021


I've got a really weird error:
qml: type: object [DEBUG-12344567890,N]
qrc:/screens/Result.qml:32: TypeError: Type error

The statements are:
console.log("type:", typeof App.result, Object.keys(App.result)) // this works
console.log("result:", JSON.stringify(App.result)); // this does not

App is an import (`import "app.js" as App`)
result is s simple JS Object: var result = { "DEBUG-12344567890": {...},"N": { ... } };

Is it possible to figure out why the stringification is failing? How could it even fail?
Better yet, can it fail with a better error. or are we locked into some terrible Javascript standard?

I added a C++ function to print it out, but the contents are as I expect.

QString Wtf::stringify(const QJSValue &var) const {
	QVariant v = var.toVariant();
	return QJsonDocument::fromVariant(v).toJson(QJsonDocument::Compact); // works
}

Any idea why that console.log is failing?






More information about the Interest mailing list