[Interest] Can't JSON.stringify an object in QML
Alexander Dyagilev
alervdvcw at gmail.com
Sat Jun 12 20:33:30 CEST 2021
Hello,
It seems your App.result is not a js object, but a c++ object derived
from QObject.
Is it?
On 5/28/2021 10:24 PM, Jason H wrote:
> 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?
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
More information about the Interest
mailing list