Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

XMLHttpRequest() not working properly with XmlListModel

$
0
0
I am using XMLHttpRequest() to get xml data from a webpage and use it in a XmlListModel. The problem that I got seems to be that XmlListModel only gets a small portion of the data as .responseText using console.log(httpReq.responseText) only gives me a partial xml data around 20% of what’s inside the xml. The other issue is that XmlListModel is always behind one call, when I first call the function it says fullscreen is undefined but when I call it again it’s fine. BUT this function needs to be called ever 1 second to get updated data as the xml file is always changing but only ever second call gives me right data. The function looks like this: XmlListModel{     id: xmlModel     query: "/root"     XmlRole{ name: "fullscreen"; query: "fullscreen/string()"}     XmlRole{ name: "volume"; query: "volume/string()"}     XmlRole{ name: "random"; query: "random/string()"}     XmlRole{ name: "state"; query: "state/string()"}     XmlRole{ name: "loop"; query: "loop/string()"}     XmlRole{ name: "repeat"; query: "repeat/string()"} }   function getVLCstatus() {     var httpReq = new XMLHttpRequest()     var url = "http://" + ip + ":" + port + "/requests/status.xml";       httpReq.open("GET", url, true);     // Send the proper header information along with the request     httpReq.setRequestHeader("Authorization", "Basic " + Qt.btoa(username + ":" + password));     httpReq.setRequestHeader('Content-Type',  'text/xml');     httpReq.onreadystatechange = function()     {         if(httpReq.readyState === XMLHttpRequest.DONE)         {             if(httpReq.status == 200)             {                 xmlModel.xml = httpReq.responseText                 console.log(xmlModel.get(0).fullscreen)             }         }     }     httpReq.send(); } Am I doing something wrong?

Viewing all articles
Browse latest Browse all 4972

Trending Articles