Save\Load struct file
I want to save and load easily a struct in a configuration file. I search on the forum and i found serialization, XML, QMap and a lot of posibilities, but i'm not sure which implement....
Basically, my application has some options and i want to be able to save and load these options, they are created in a struct with integer, double and QString values, and i don't know if there's some way to do it easly or which is recomended.
I store a few different types of things. I store application configuration data such as where was a particular dialog displayed last time it was open. For that, I use QSettings. This will auto-magically persist values that you set and make them available based on how your startup code identifies your application; for example:
QCoreApplication::setApplicationName("Link Backup ADP");
I also have individual configuration files that I don't consider application specific. For example, in the Link Backup software, I store backup-sets that tell me what to backup, where to put the backup, what to include, etc. I have XML files for multiple things that I may choose to backup separately. For this, I chose to save the configuration information as XML. I use a QXmlStreamReader and then I have routines that can read to and from an XML stream.
I could have just as easily written a simple class to read / write "property" files if Qt does not already have one, store it in a map / dictionary. Don't know if that would be easier (or more difficult) for you.
Looks like the QSettings object allows you to specify a specify "ini" file and the ini format. So, you would not need to write your own method to handle it. You would still need to worry about configuring objects from the QSettings object and vice-versa, but that should not be that big of a deal; probably easier than doing it using XML.
You could also try converting your struct to a QJsonObject and storing it in a QJsonDocuent (the downside is that integers will be stored as doubles). Example: http://qt-project.org/doc/qt-5/qtcore-savegame-example.html
I did it with the json method.