Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 3 Support (Qt 5) › File input/Output

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #12556



    is there any way to write to files from Felgo.

    I want to use an Android phone GPS module to write times and locations to a file (ideally to a Dropbox folder).




    Hi Andy,

    we have a (currently undocumented) fileUtils context property, which you can use for that.

    bool success = fileUtils.writeFile("myFile.txt", "myFileContentString")

    you can also use it to read a file as Chris mentioned in this post.

    Note that this is not officially supported as of now and you should carefully test your app if you use this!


    Alternatively, you can implement something that fits your needs yourself in C++. Here is a simple example on how to do it.


    Please let me know if that helps you or you need any further help!



    • This reply was modified 8 years, 4 months ago by  Lorenz.
    • This reply was modified 8 years, 4 months ago by  Lorenz.


    Excellent! Thanks Lorenz.

    On a quick test the fileUtils property seems to work fine for my purposes, and the stack overflow link shows where I was going wrong trying the C++ route  – I didn’t know to

    #include <QtQml>            // If you use Qt5

    Davide Manuel

    Hi there.

    First of all, sorry for my english.

    I’m trying to use fileUtils.writeFile to replace a custom .json file.

    But, even if fileUtils.writeFile returns success the file isn’t changed.

    What could it be?


    Felgo Team

    Are you sure you are writing / overwriting the correct file? (and path)

    If you are using a relative path, the default user documents folder is prepended/used, as this ensures a writeable path on different platforms.



    Davide Manuel

    Hey, Günther.

    I’m almost 100% sure that i’m using the right file/path, since i can read the same file/path.

    I read the file and after change the values i use the writeFile to overwrite it. But, nothing happens.

    In time, it’s my first v-play project and i changed the code to use Storage component and that solves my problem.

    But, i’m still looking how to fix the writeFile issue.

    Which is the default user documents folder  in the project struture?







    Hi Davide,
    Just checked some simple demo for fileUtils and, it looks like, it works.

    import Felgo 3.0
    import QtQuick 2.0
    App {
        // You get free licenseKeys from http://felgo.com/licenseKey
        // With a licenseKey you can:
        //  * Publish your games & apps for the app stores
        //  * Remove the Felgo Splash Screen or set a custom one (available with the Pro Licenses)
        //  * Add plugins to monetize, analyze & improve your apps (available with the Pro Licenses)
        //licenseKey: "<generate one from http://felgo.com/licenseKey>"
        NavigationStack {
        Page {
            title: qsTr("Main Page")
            Column {
                width: parent.width
                TextEdit {
                    id: editableArea
                    width: parent.width
                    height: 300
                    text: "Hello, start typing here ..."
                    font.family: "Helvetica"
                    font.pointSize: 20
                    color: "blue"
                    focus: true
                Rectangle {
                    color: 'blue'
                    width: 150
                    height: 50
                    radius: 25
                    x: parent.x / 2
                    Text {
                        text: 'Save current text'
                        anchors.centerIn: parent
                        color: '#fff'
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            fileUtils.writeFile(Qt.resolvedUrl("newFile.txt"), editableArea.text)
                TextEdit {
                    id: fileContentArea
                    readOnly: true
                    text: 'Loading ....'
                    function readCurrentFileConent() {
                        fileContentArea.text = fileUtils.readFile(Qt.resolvedUrl("newFile.txt"))
                    Component.onCompleted: {

    Looks like, by default, Qt searches relatively from to the fiel from which you use the method.
    I created new project Qt Apps, and just changes Main.qml.
    The file I edit is in qml/newFile.txt , relatively to Main.qml which is also in qml/Main.qml
    Try this one, maybe will help you



    One last thing Davide,
    Remember that Qt is executed inside your build directory, not in the place where you edit files.
    Definitely you have something like build-youProject-Desktop-Qt5.7 , or similar.
    Since the app is executed in the build direcotry, the file in build directory is being changed, not in the directory where you edit your sources.
    To see where Qt builds your app check Project(left menu)->your kit “Build”->and look for build directory option.
    The file you want to read/write will be in that directory.


    Davide Manuel

    Hi Marcin,

    thx for the help.  You’re right. The file was in the build directory.

    Thx again.


Viewing 9 posts - 1 through 9 (of 9 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded