Important: Please read the Qt Code of Conduct -

Read file using Utils.readFile when file is in different location from main qml

  • I am trying to read contents of file using Utils.readFile(fileName). The file is stored in a folder different from the location where I call the qml file from. So I tried this:
    var storageData = Utils.readFile(Qt.resolvedUrl("four/u-boot-env.bin"))
    if (!storageData)
    throw new Error("Could not read from file '")
    I get the following error:
    C:/work/sam-ba_3.1.4/qml/SAMBA/Applet.qml:604: Error: Could not read from file '
    How can i pass to Utils.readFile, a file name stored in a different folder from where the main qml is called from.
    Thanks so much for the help.

  • Qt Champions 2017

    What is this Utils.readFile function ? What argument it takes ? Does it take the URL as argument ? What is the return value of that function ?

  • Hi,

    You could also check out V-Play's fileUtils context property.

    bool success = fileUtils.writeFile("myFile.txt", "file content");
    var text = fileUtils.readFile(Qt.resolvedUrl("myFile.txt"))

    Read more on this thread.

    V-Play can also help you with lots of other things when developing apps or games, check it out here.


Log in to reply