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. Best way to store downloaded XmlModel in LocalStorage with qml
Qt 6.11 is out! See what's new in the release blog

Best way to store downloaded XmlModel in LocalStorage with qml

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gloww
    wrote on last edited by
    #1

    Hey there,

    I am building an Android app. The app should display different text and image contents from the web. Caught via XmlListModel.
    I want to cache these data to give the user the possibility to check the content while beeing offline also.
    What is the best way to do this?
    I found the LocalStorage option which gives me the possibility to access a database via JS, but i am not sure how to ave a model with this plugin.
    Do i have to delegate through my model and then safe it item by item into the db? And how do i save images?
    I am getting the feeling that best way to do the task would be to catch the data in c++ put it in the database and then from qml simply view it.
    What do you think?

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

      If you are using xmlListModel, you need to process the model data and store it appropriately localStorage.

      Other good option is to query the data in C++ using network classes and store the data in into xml format itself on the disk. These xml files can be set as source(using xml attribute) for XMLListModel.

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gloww
        wrote on last edited by
        #3

        It would be a really great feature to have something like a cache in Quick / QML.

        I will now open an url with QNetworkAccessManager, then save it in an temp folder, then open it to store it in a sqlite tabel and then again write it to an xml file again, all from c++.

        Is that the right way when i want to save all the data in the app and only update it from time to time with new content via XML?

        is there a way to add items to existing XML documents in qt? So far i only find ways to create a new document.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

          Did you get a chance to look at QDomDocument and it's methods ?

          Also why do you want to store in db ? You can directly store the xml files into disk and access it whenever you want ?

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gloww
            wrote on last edited by
            #5

            The step with the db is only neccessary bcause i was not sure how to add elements to an existing xml document. I think QDomDocument does this job, so i can directly update a xml file. What about images?
            Would you download them and put them in a folder, or is there an easier way with QAbstractNetworkCache, QNetworkDiskCache, QDeclarativeImageProvider? They all seem quite complicated or limited and i think simply downloading images and store them in a folder seems more easy.

            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