Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Size of serialized data.
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] Size of serialized data.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views 2 Watching
  • 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.
  • HarbH Offline
    HarbH Offline
    Harb
    wrote on 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?

    JKSHJ 1 Reply Last reply
    0
    • HarbH Harb

      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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on 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
      • HarbH Offline
        HarbH Offline
        Harb
        wrote on 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

        • Login

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