Local files
Is it also possible to load local (XML/JSON) files using the XMLHttpRequest. For example a local file named “colors.json” can be loaded using:
We use this to read a color table and display it as a grid. It is not possible to modify the file from the Qt Quick side. To store data back to the source we would need a small REST based HTTP server or a native Qt Quick extension for file access.
For this to work, the QML_XHR_ALLOW_FILE_READ
must be set and enabled (set to 1
). You can do so by running:
The issue is when allowing a QML application to read local files through an XMLHttpRequest
, hence XHR
, this opens up the entire file system for reading, which is a potential security issue. Qt will allow you to read local files only if the environment variable is set, so that this is a concious decision.
Instead of using the XMLHttpRequest
it is also possible to use the XmlListModel to access local files.
With the XmlListModel it is only possible to read XML files and not JSON files.
Last updated