Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Read file using Utils.readFile when file is in different location from main qml
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 832 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swapna
    wrote on last edited by
    #1

    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 '
    file:///C:/work/trainings/crank/Extras/BOOT/four/u-boot-env.bin'
    
    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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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 ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4
      • LorenzL Offline
        LorenzL Offline
        Lorenz
        wrote on last edited by
        #3

        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.

        Cheers,
        Lorenz

        Developer @ V-Play Engine - http://v-play.net/qt

        V-Play simplifies

        • Game Development with Qt
        • Mobile App Dev with Qt esp. iOS & Android

        What others say
        V-Play scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved