JavaScript Fetch API
Unsolved
QML and Qt Quick
-
Is the Fetch API supported in Qml? (Qt 5 / Qt 6) https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
This code example gives an error when executed in Qml:
const fetchPromise = fetch("https://ghibliapi.herokuapp.com/people"); fetchPromise.then(response => { return response.json(); }).then(people => { console.log(people); });
The error message:
qrc:/main.qml:49: ReferenceError: fetch is not defined
Tried with Qt 5.15.2 and 6.3.
-
@None-None-None
Never tried if it is working, as I still use my old helper method and pass a function into the callback:function doRequest(url, method, callback) { var xhr = new XMLHttpRequest() xhr.onreadystatechange = (function (myxhr) { return function () { if (xhr.readyState === XMLHttpRequest.DONE) callback(myxhr) } })(xhr) xhr.open(method, url, true) xhr.send('') }