Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. JavaScript Fetch API
Qt 6.11 is out! See what's new in the release blog

JavaScript Fetch API

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.4k Views
  • 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.
  • N Offline
    N Offline
    None None None
    wrote on last edited by
    #1

    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);
    });
    

    (Via: https://medium.com/@armando_amador/how-to-make-http-requests-using-fetch-api-and-promises-b0ca7370a444)

    The error message:

    qrc:/main.qml:49: ReferenceError: fetch is not defined
    

    Tried with Qt 5.15.2 and 6.3.

    L 1 Reply Last reply
    0
    • N None None None

      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);
      });
      

      (Via: https://medium.com/@armando_amador/how-to-make-http-requests-using-fetch-api-and-promises-b0ca7370a444)

      The error message:

      qrc:/main.qml:49: ReferenceError: fetch is not defined
      

      Tried with Qt 5.15.2 and 6.3.

      L Offline
      L Offline
      lemons
      wrote on last edited by
      #2

      @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('')
      }
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved