How to read FILE content in QML?

I just need something like Fstream to read an IO file in QML. Why is there no IO file?

+7
source share
4 answers

If your file is plain text, you can use XMLHttpRequest. For example:

var xhr = new XMLHttpRequest; xhr.open("GET", "mydir/myfile.txt"); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { var response = xhr.responseText; // use file contents as required } }; xhr.send(); 
+8
source

I know this is an old question, but you may be interested in the answer. Here it is: Reading a line from a .txt or .csv file in qml (Qt Quick)

In short, you explained here how to read files in QML: http://www.developer.nokia.com/Community/Wiki/Reading_and_writing_files_in_QML

All you need to do is extend QML with C ++.

+4
source

QML does not have built-in I / O. But judging by the tone of your post, you already knew that.

How to read FILE content in QML?

You can extend the functionality of QML with C ++.

The QML getting started guide from the Qt reference documentation shows how to create a text editor. This includes file input / output using C ++.

Why is there no file input / output?

Since QML is based on JavaScript, JavaScript also does not have built-in I / O.

QML is designed as an easy way to create a user interface. You need a real program to do the rest.

+3
source

What do you want to read for a file? ... if its simple data ... then you are probably better off using the QML offline memory API. Take a look at this section here .

If you want to deploy db with your application, read this talk .

If you really want to read the file as before, learn C ++ and expose your code in QML. Then it goes beyond my answer.

0
source

All Articles