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. Save\Load struct file
QtWS25 Last Chance

Save\Load struct file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.1k Views
  • 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.
  • A Offline
    A Offline
    avmg
    wrote on last edited by
    #1

    Hi,

    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.

    Thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pitonyak
      wrote on last edited by
      #2

      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::setOrganizationDomain("pitonyak.org");
      QCoreApplication::setOrganizationName("Pitonyak");
      QCoreApplication::setApplicationName("Link Backup ADP");
      QCoreApplication::setApplicationVersion("1.0.2");@

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pitonyak
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          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

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • A Offline
            A Offline
            avmg
            wrote on last edited by
            #5

            Done!

            I did it with the json method.

            Thanks!

            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