Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Using external Json file in QML [Qt5/QML2]

    QML and Qt Quick
    2
    3
    2989
    Loading More Posts
    • 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
      Kelteseth last edited by

      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 Reply Quote 0
      • C
        chrisadams last edited by

        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 Reply Quote 0
        • K
          Kelteseth last edited by

          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 Reply Quote 0
          • First post
            Last post