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. [SOLVED] Size of serialized data.

[SOLVED] Size of serialized data.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 886 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.
  • H Offline
    H Offline
    Harb
    wrote on 20 Sept 2015, 12:34 last edited by Harb
    #1

    Hi guys!

    Now I am writing a code for saving data into the file. Usually data files have header at the beginning where table with offsets is located. For example I want to save 10 objects into my file, each object have quite large size. Size of each objects could be different. So, to read one object I need to know its offset into the file (If I don't want to read every object before). Of course I can do that manually, just by calculating size of each serialized object, but at this point it seems that I will have to do a lot of tedious work with sizeof(), because each object has a lot of related dynamic data. My question is what is the best way to generate this table while writing file, may be there are some sort of patterns which are used in this case, or special classes/functions in Qt?

    J 1 Reply Last reply 20 Sept 2015, 14:38
    0
    • H Harb
      20 Sept 2015, 12:34

      Hi guys!

      Now I am writing a code for saving data into the file. Usually data files have header at the beginning where table with offsets is located. For example I want to save 10 objects into my file, each object have quite large size. Size of each objects could be different. So, to read one object I need to know its offset into the file (If I don't want to read every object before). Of course I can do that manually, just by calculating size of each serialized object, but at this point it seems that I will have to do a lot of tedious work with sizeof(), because each object has a lot of related dynamic data. My question is what is the best way to generate this table while writing file, may be there are some sort of patterns which are used in this case, or special classes/functions in Qt?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 20 Sept 2015, 14:38 last edited by JKSH
      #2

      Hi @Harb,

      My question is what is the best way to generate this table while writing file

      That really depends on how your data is structured, and how you want to use it.

      Could you provide more details?

      may be there are some sort of patterns which are used in this case, or special classes/functions in Qt?

      There are many ways to save data to disk. Here are 3 options:

      • You can use QDataStream to convert Qt objects to/from raw bytes: http://doc.qt.io/qt-5/qdatastream.html
      • You can use Qt SQL classes to read/write table data: http://doc.qt.io/qt-5/examples-sql.html
      • You can convert your data to/from a JSON document: http://doc.qt.io/qt-5/qtcore-json-savegame-example.html

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

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Harb
        wrote on 21 Sept 2015, 21:35 last edited by
        #3

        @JKSH Tnx!
        I think I managed to overcome this problem, so there is no need in further discussion of details : )/
        tnx for links!

        1 Reply Last reply
        0

        3/3

        21 Sept 2015, 21:35

        • Login

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