Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

JSON string to QML, "null" values converted to QVariant(void*) with QJSEngine::toScriptValue

$
0
0
hello, I don’t know if this is bug but i’m trying to convert a JSON string to a QJSValue to use it directly in QML. it works great so far but I have some weird results with “null” values in the JSON data. minimal example setup: simple JSON object as string: { “test”: null } so I convert that to a JSValue like this: QJSValue data = QJSEngine().toScriptValue(QJsonDocument::fromJson(”{ \“test\”: null }”).object()); I didn’t found a doc but it seems to work to convert a QJsonObject to QJSValue. my problem now is that the “test” property will be QVariant(void*) and not simply “null” as expected in JavaScript. First converting the QJsonDocument to QVariant and than to QJSValue works (the value is then QVariant(Invalid) which gets converted to “null” in JS) but I think that is an unnecessary step? also I get a segmantation fault for some QVariantMaps, see my call stack here: 0 QV4::PropertyHash::lookup qv4internalclass.cpp 118 0×826b8ed 1 QV4::InternalClass::addMember qv4internalclass.cpp 211 0×826bd5d 2 QV4::Object::insertMember qv4object.cpp 297 0×828c504 3 QV8Engine::variantMapToJS qv8engine.cpp 595 0×835984c 4 QV8Engine::metaTypeToJS qv8engine.cpp 688 0×8359e48 5 QV8Engine::variantToJS qv8engine.cpp 918 0×835aef1 6 QV8Engine::variantMapToJS qv8engine.cpp 596 0×8359869 7 QV8Engine::metaTypeToJS qv8engine.cpp 688 0×8359e48 8 QV8Engine::variantToJS qv8engine.cpp 918 0×835aef1 9 QV8Engine::metaTypeToJS qv8engine.cpp 698 0×8359f5f 10 QJSEngine::create qjsengine.cpp 363 0×8252b85 11 QJSEngine::toScriptValue<QVariant> qjsengine.h 82 0×40e7b3 … <More> any ideas?? :) one last thing, in general is it better to convert a QJsonDocument to QJSValue or just use an QVariant and pass that to QML (via Qt signal argument)? Edit: I use Qt 5.2 mingw on windows, but I don’t think that matters much here

Viewing all articles
Browse latest Browse all 4972

Trending Articles