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. Using external Json file in QML [Qt5/QML2]
QtWS25 Last Chance

Using external Json file in QML [Qt5/QML2]

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.2k Views
  • 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.
  • K Offline
    K Offline
    Kelteseth
    wrote on last edited by
    #1

    Hey Qt-Project members

    I've tried the last 3 hours getting a external Json file loading in my QML / Javascript logic.

    @ var jsonObj ={"test" : ["a","b","c","d","e","f","g","h"],}
    ...
    console.log(jsonObj.test[0])@

    This works quite well but is there a way to store the Json data in a separate file?

    thanks
    Eli

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Hi,

      Use the LocalStorage submodule of QtQuick2 to store things to a database. Alternatively, write your own simple file storage QObject-derived type, and expose it as a singleton type or ordinary type, and use it to write out the string to file. You can use JSON.parse() and JSON.stringify() in the JS environment supported by QML in Qt5.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kelteseth
        wrote on last edited by
        #3

        Thanks but it looks like the easiest way to solve this is to write an Json object in an normal javascript file :)

        Eli

        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