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 / Javascript XMLHttpRequest issues in Qt 5 beta 2
QtWS25 Last Chance

Qml / Javascript XMLHttpRequest issues in Qt 5 beta 2

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 3.2k 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.
  • C Offline
    C Offline
    CLarge
    wrote on last edited by
    #1

    As of the beta 2 release I'm seeing some strange issues when using XMLHttpRequest to issue various rest requests to a device. Specifically it seems that the callback function I've specified for onreadystatechange is not always called.

    The general structure of the code goes like this. I have a model object defined in javascript and this object has several functions for get, put, etc that allow the model data to be in sync with that of a server which is the source of this information. In the get function I have the following (distilled version):

    @model.prototype.get = function (resource, callback) {
    var request = new XMLHttpRequest();

    request.onreadystatechange = function () {
        if (request.readyState === 4) {
            if (request.status >= 200 && request.status < 300) {
                // do stuff here
            }
            else {
                // do other stuff here
            }
        }
    };
    
    request.open("GET", "http://" + this.ipAddress + "/rest/" + resource, true);
    request.withCredentials = true;
    request.timeout = model.timeout;
    request.send();
    

    }@

    This code lives in foo.js and is then imported into bar.qml. In bar.qml I trigger a call to get through a button press, the call succeeds and with log messages I can see that everything executes correctly to issue the get, however the onreadystatechange callback is never executed.

    Now, if I move all of this code into bar.qml it executes perfectly every time.

    Anyone have any idea what is going on? This really smells of an "interesting" javascript bug in beta 2 but I haven't been able to distill this down any further to determine the cause.

    Thanks,
    Chris.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      I'm not 100% certain, but it may be due to having no valid evaluation context at the time of the callback. In most cases, this doesn't actually cause any issues (because the code which runs doesn't necessarily depend on the evaluation context), but some functions (like Qt.createObject()) will crash and others will behave badly.

      See fdeee38b in qtdeclarative.git.
      File a bug with a minimal testcase if you're sure that it's doing something wrong.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paazmaya
        wrote on last edited by
        #3

        Hi,
        At least here it is stated that the callback should not be denifed before calling "open"
        https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#Properties

        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