Take the 2-minute tour ×

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

share|improve this question
add comment

4 Answers

QML has no built-in file I/O. But - judging from the tone of your post - you already knew that.

How do I read in FILE contents in QML?

You can extend QML's functionalities using C++.

The Getting Started Programming with QML tutorial from the Qt Reference Documentation shows you how to build a text editor. This includes file I/O using C++.

Why is there no file I/O?

Because QML is based on JavaScript, and JavaScript has no built-in file I/O either.

QML is designed as an (easy) way to build a user interface. You need an actual program to do the rest.

share|improve this answer
add comment

If your file is plain text you can use XMLHttpRequest, see this example.

share|improve this answer
This also works for other plain text based formats, eg. json –  OlliM Sep 20 '13 at 7:41
add comment

What do you want to read the file for?... if its simple data.. then you are probably better off using QML Offline storage API. Look for that section here.

If you want to deploy a db with your application read this conversation.

If you really want to read the file still, learn C++ and expose your code to QML. That, then, is beyond the scope of my answer.

share|improve this answer
add comment

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

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

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

share|improve this answer
add comment

Your Answer


