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. QML does not see httprequest.readyState
Forum Updated to NodeBB v4.3 + New Features

QML does not see httprequest.readyState

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 230 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    hello...
    so scenario:

    property var xmlrequest = new XMLHttpRequest()
    
    function triggerRequest() {
        xmlrequest.abort();		// cancel old call if any
        xmlrequest.onreadystatechange() {
            console.log("readystateChanged to:", xmlrequest.readyState);    // properly print 1, then 2, then 3, then 4
        }
        MODEL.feed_xmlhttp.onload = function() {
            console.log("loaded, so status should be 4", xmlrequest.readyState); // properly debugs 4
        }
        xmlrequest.open("GET", some_url, true);
        xmlrequest.send();
    }
    
    function doSomething() {
        console.log("triggered");
    }
    property bool checkIfIsFinishedProcessing: xmlrequest.readyState
    onCheckIfIsFinishedProcessingChanged: if (xmlrequest.readyState == 4) { doSomething(); }  // this does nothing (XMLHttpRequest.DONE also does not work, === operator for both (4 and DONE) also dont)
    onCheckIfIsFinishedProcessingChanged: console.log(typeof xmlrequest.readyState, xmlrequest.readyState)  // properly debugs "number" as type, and then 1, 2, 3, 4 as it changes...
    

    so what do I do wrong here?

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Please read the documentation about the XMLHttpRequest type.

      The important part is:
      Assign a callback function to the onreadystatechange signal handler.

      More specifically, readyState doesn't have a change signal. Furthermore, the (redundant) binding to checkIfIsFinishedProcessing is crippled. If it would work at all, it would bind an enumeration to a boolean. Comparing the result to the int value 4, is also not a recommended practive. Better use the enum value Done for better code readability.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shokarta
        wrote on last edited by
        #3

        So can i link my qml variable outside of that JS function to the onreadystatechange so once it changes it triggers something im qml?

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          I am not sure, what your question exactly means.
          You have to implement a function and register it as the callback function for state changes.
          Totally up to you, what that function does/triggers/changes/debugs.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0

          • Login

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