I need open a text file and read it's contents line by line and store each lines in a string list in qt quick 2.2.
Can every one help me?
QML provides a partially-functional version of XMLHttpRequest. It's good enough to load text files from the local files system, but that's about it. An example:
var request = new XMLHttpRequest()
request.open('GET', 'test.txt')
request.onreadystatechange = function(event) {
if (request.readyState == XMLHttpRequest.DONE) {
lines = request.responseText.split('\n') // Assuming you've defined
} // lines as a property
}
request.send()
Note that only a portion of the XMLHttpRequest1 interface is supported. Notably, only asynchronous requests are allowed. I've written some more details here.
request.responseText
, but only after request.readyState advances to XMLHttpRequest.DONE
. XHRs are always asynchronous in QML, so you have to handle this in a callback.
Dec 22, 2014 at 19:56