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. [SOLVED]multiple XMLHttpRequest fires in random order

[SOLVED]multiple XMLHttpRequest fires in random order

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

    I have 3 different files opened, using XMLHttpRequest in different functions, that parses data. It seems, that they are finishing reading of files in different order, than associated functions, that are called with XMLHttpRequest in them. It seems, that biggest of files is finished last no matter what order it takes in calls.

    It is crucial to complete parsing data of first three, before starting to parse 4th, as it uses and modifies global extracted data from first three files. Initially it worked - sometimes I had to restart call, but there was a random chance, that all data was read before it was modified, so I thought that it was because of bad connection, but now it does not read biggest file in time at all. The biggest file is read AFTER all other functions - even the ones, that were written in code after the biggest file reader.

    Sizes of files for comparision(in bytes):

    1. 8 003
    2. 6 329 - this finishes after first, because there is more parsing involved, than in first file
    3. 139 219 - takes a lot longer than couple of seconds

    1. 32 693 - just started to process and should be read last.
    1 Reply Last reply
    0
    • G Offline
      G Offline
      glicanear
      wrote on last edited by
      #2

      The idea was to use JavaScript to the timed delays, but apparently after consulting resources about QML it seems, that the only way is using QML events and call 4th function alone after first three are done.

      Anyway, to beginners of JavaSript no example mentions this XMLHttpRequest nonreliable behaviour, but for sure - in most cases it is required to read more than just one file and this behaviour is weird for human logic, as it is imagined that all those XMLHttpRequest are run in sequence - not all at once, as it really happens.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glicanear
        wrote on last edited by
        #3

        The file loading function that I wanted looks like this(allows to load only one file after another):

        @//WorkerScript.js

        Qt.include("Script.js") //scripts are in plain JavaScript

        function loadFile(processFunc, fileName)
        {

        var request = new XMLHttpRequest()
        request.open('GET', fileName)
        request.onreadystatechange = function(event)
        {
            if (request.readyState == XMLHttpRequest.DONE)
            {
        
                WorkerScript.sendMessage( {response: processFunc(request.responseText)} );
        
            }
        }
        request.send();
        

        }@

        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