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 document in a qml object
Forum Updated to NodeBB v4.3 + New Features

Json document in a qml object

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.5k 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,

    I am new to Qt Quick, so please excuse my beginner question (I come from C++)...

    I am trying to create a non visible component (QtObject) which will contain a number of information that my application needs. I am trying to do as much as I can in QML and not "drop back" to C++

    This data is saved as a Json file and I wanted to create a wrapper around a JsonDocument to access the data.
    Something around the lines of:
    However, QML does not seem to like the JsonDocument "type". What would be the proper way to achieve what I want?

    import QtQuick 2.0
    QtObject {
    property string jsonString: "{"a":"A whatever, run","b":"B fore something happens"}" // temporary to test
    JsonDocument { is: src; source: String }
    property string str1: src.a
    property string str2: src.b
    }

    Thanks!

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      Cant help you with Json but this may interest you https://wiki.qt.io/Qml_Styling

      C 1 Reply Last reply
      0
      • ODБOïO ODБOï

        Cant help you with Json but this may interest you https://wiki.qt.io/Qml_Styling

        C Offline
        C Offline
        Cyrille de Brebisson
        wrote on last edited by
        #3

        Hello,

        Cant help you with Json but this may interest you https://wiki.qt.io/Qml_Styling

        Thanks, this article on Singleton was actually useful!

        Cyrille

        1 Reply Last reply
        0
        • sneubertS Offline
          sneubertS Offline
          sneubert
          wrote on last edited by
          #4

          Hi Cyrille,
          the JavaScript Host Environment in QML provides the standard ECMAScript built-ins (http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html).

          There´s a JSON type you can use in javascript expression like
          var jsonObj = JSON.parse(yourJsonString)
          After parsing you can access the json objects for your example like jsonObj.a
          If you really need a QObject wrapper, you could parse the json at Component.onCompleted event
          and provide javascript functions to access your json objects.

          1 Reply Last reply
          1

          • Login

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