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. The most elegant way to handle xml serialization

The most elegant way to handle xml serialization

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 946 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.
  • enemyofthedawnE Offline
    enemyofthedawnE Offline
    enemyofthedawn
    wrote on last edited by
    #1

    What's in your opinion the most elegant way to handle xml serialization in Qt?

    Should I use QDomDocument and similar classes from the same group or maybe QXmlStreamReader, QXmlStreamWriter and linearly serializing, deserializing my custom class? I'd like to note that my class is not QObject class.

    I need simple save and load in classes I need to serialize and deserialize and nothing more.

    Should I create some interface (pure-abstract class) for that?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      For a larger number of classes that need serialization, i prefer a
      base class design with virtual functions allowing for polymorph saving and loading. This base class also give helper functions to save/load a vectors and other convenience functions to minimize the amount of code needed in the child/using classes.

      However, for a few classes, nothing wrong with just save / load directly.

      I like QDomDocument interface and its easy to construct the tree but it can also be a bit verbose.
      QXmlStreamWriter can look really tight but could be messy for
      deep/complex structures as its more flatten in expressing the actual (data) tree. (IMHO)
      If we go with "KISS", i would go with QXmlStreamWriter and check out how it felt with a few test classes.

       stream.writeStartElement("bookmark");
       stream.writeAttribute("href", "http://qt.nokia.com/");
       stream.writeTextElement("title", "Qt Home");
       stream.writeEndElement(); // bookmark
      
      1 Reply Last reply
      3

      • Login

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