Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Best way to store user data



  • 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?


  • Lifetime Qt Champion

    @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).


Log in to reply