Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best way to store user data
Qt 6.11 is out! See what's new in the release blog

Best way to store user data

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 785 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.
  • LorenDBL Offline
    LorenDBL Offline
    LorenDB
    wrote on last edited by
    #1

    I don't think that it's a great idea to store potentially large pieces of user data in QSettings. Also, using QSettings for storing user data doesn't make it easy to export saved data. Therefore, I'm looking for a good way to store user data. I tried QXmlStreamReader and Writer, but the Writer doesn't appear to be good at inserting data without actually erasing anything that was already there. The Qt JSON stuff looks promising, but there isn't any direct plumbing to files. Is there any dedicated save file class or do I need to just manually load/dump JSON from file?

    jsulmJ 1 Reply Last reply
    0
    • LorenDBL LorenDB

      I don't think that it's a great idea to store potentially large pieces of user data in QSettings. Also, using QSettings for storing user data doesn't make it easy to export saved data. Therefore, I'm looking for a good way to store user data. I tried QXmlStreamReader and Writer, but the Writer doesn't appear to be good at inserting data without actually erasing anything that was already there. The Qt JSON stuff looks promising, but there isn't any direct plumbing to files. Is there any dedicated save file class or do I need to just manually load/dump JSON from file?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @LorenDB said in Best way to store user data:

      Is there any dedicated save file class or do I need to just manually load/dump JSON from file?

      JSON is simply a string, so you can use QFile to read the file content and then https://doc.qt.io/qt-5/qjsondocument.html#fromJson . To write to file you again can use QFile and https://doc.qt.io/qt-5/qjsondocument.html#toJson

      "Writer doesn't appear to be good at inserting data without actually erasing anything that was already there" - you cant insert anything in a file, you have to rewrite the file if you want to insert (at least rewrite the part where you're inserting).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4

      • Login

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