Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
4.8.0
-
None
Description
When using an XmlHttpRequest within QML, the onreadystatechange only gets triggered 3 times (upon success): once when the headers have been received, once when loading the body, and once when done. However, if there is a big resource loaded, the event that triggers onreadystatechange should be fired every time there is new data, which is what Chrome and Firefox do.
To reproduce:
<html> <script type="text/javascript"> var postman = new XMLHttpRequest(); postman.open("GET", "http://localhost/path/to/bigfile.txt"); postman.onreadystatechange = function() { alert("state changed to " + postman.readyState + " status: " + postman.status + " response length: " + postman.responseText.length + " response text:\n" + postman.responseText); } postman.send(); </script> </html>
And then load this html page from localhost as well (watch out for same-origin-policy).
Proposed fix:
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 3bc9100..5860422 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -1226,9 +1226,9 @@ void QDeclarativeXMLHttpRequest::downloadProgress(qint64 bytes) m_responseEntityBody.append(m_network->readAll()); if (wasEmpty && !m_responseEntityBody.isEmpty()) { m_state = Loading; + } QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); - } } void QDeclarativeXMLHttpRequest::error(QNetworkReply::NetworkError error)