Using external Json file in QML [Qt5/QML2]

  • 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"],}

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


  • 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.


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


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.