Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. JSON string to QML, "null" values converted to QVariant(void*) with QJSEngine::toScriptValue
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xander84
    wrote on last edited by
    #1

    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 0x826b8ed
    1 QV4::InternalClass::addMember qv4internalclass.cpp 211 0x826bd5d
    2 QV4::Object::insertMember qv4object.cpp 297 0x828c504
    3 QV8Engine::variantMapToJS qv8engine.cpp 595 0x835984c
    4 QV8Engine::metaTypeToJS qv8engine.cpp 688 0x8359e48
    5 QV8Engine::variantToJS qv8engine.cpp 918 0x835aef1
    6 QV8Engine::variantMapToJS qv8engine.cpp 596 0x8359869
    7 QV8Engine::metaTypeToJS qv8engine.cpp 688 0x8359e48
    8 QV8Engine::variantToJS qv8engine.cpp 918 0x835aef1
    9 QV8Engine::metaTypeToJS qv8engine.cpp 698 0x8359f5f
    10 QJSEngine::create qjsengine.cpp 363 0x8252b85
    11 QJSEngine::toScriptValue<QVariant> qjsengine.h 82 0x40e7b3
    ... <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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      feldifux
      wrote on last edited by
      #2

      I'm having the same issue: code from Qt 4 did not work because of that change.
      This bug should be fixed though with Qt 5.3 RC1 (ETA next week): https://qt.gitorious.org/qt/qtdeclarative/commit/ff0857541d5d391c7c03cce5893b41dd9b35e7fa

      Cheers, Chris

      Founder of Felgo SDK - http://felgo.com/qt

      Felgo simplifies

      • Mobile App Dev with Qt esp. iOS & Android
      • Game Development with Qt

      What others say

      Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved