Writing and Reading JSON files with QML

• Dec 26, 2018 - 13:57

Hi, I'm upgrading my Tunings and Temperaments plugin to allow the user finer control over the tunings.

I'd like the user to be able to save their own tunings locally, for sharing and/or later re-use.

Ideally I'd like the saved files to be JSON, but that's not an absolute requirement.

Searching through the QML documentation I can see no obvious way to do this without also writing C++, which is a non-starter for a plugin.

Have I missed something, or should I turn this in to a feature request?


Comments

In reply to by XiaoMigros

JSON files are JavaScript… that being said, they lack any assignment, so the import statement would probably not work.

If you can load the file into a string, the standard JSON.parse(s) works…

> but only from network as QML doesnot have direct access to local file system

… according to the Qt forum.

Your best bet is to transform the JSON to add a line before the first that simply says exports.default = (IIRC, untested), then use import. This can be done programmatically at release build time, if needed (tiny shell script or something).

Do you still have an unanswered question? Please log in first to post your question.