prolink007
prolink007

Reputation: 34534

Saving user's data for my application

I was wondering what would be the correct method for saving all user data for an application I am working on. The application is in QT. The user inputs a lot of data into the application and the data will be different for every user. I want the ability for the user to save all the current data to a file that can be user by the loaded by the application again once the user wants to use it again or use it on another computer running the application.

What would be the correct and best way to do this? Do I need to use xml format? And then use the xmlreader for QT? Or do I just need to create my own file format and just use the stream to just read everything in. The data in the file will need to be labeled, because it will need to put the data in certain spots on the gui. And the user has the option to dynamically create boxes and tabs that hold certain information.

If you need any more information, please let me know.


A short example:

I am not only reading gui locations. But the contents of those. For instance. The user is able to create tabs that contain edit text boxes. And those tabs are associated with items that are in a list. When the user clicks on an item in the list the user will be presented with a whole set of new tabs. And each tab has some editing forms. The file will need to contain what is in the list, what tabs the user has created under each item in that list and the contents of each tab associated with the tab of each item in the list.

Upvotes: 0

Views: 418

Answers (2)

Bruce
Bruce

Reputation: 7132

Another great solution is to use internal database implementation (QSQL on top of sqlite). Compared to the xml solution, it might be more versatile (update when needed, can use external keys). Qt has some rgeat examples about using it aas well.

In terms of dependencies, XML solution will require you to use xml and xmlpatterns (if you want to validate stuff), whereas sqlite solution will require QSQL + sqlite plugin. I think that sqlite guarantees atomicity of writing , thus preventing corruption of data (think : the user is killing the app while it's saving).

Upvotes: 2

Chris
Chris

Reputation: 484

In essense, yes you'll be creating your own file format, but the actual content can just be XML in whatever scheme you need. Then you can use Qt's built-in XML processing capabilities to pull the heavy lifting of parsing the text (I personally prefer the DOM model, so I use QDomDocument as my base point), and you'll just need to worry about parsing things to and from the individual nodes.

The Qt framework has some great XML samples if I remember correctly that helped me get off the ground almost immediately. Hope they help!

Upvotes: 2

Related Questions