Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. XML vs JS in Qt. What is more "native" for Qt?
Qt 6.11 is out! See what's new in the release blog

XML vs JS in Qt. What is more "native" for Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 2.6k Views 4 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.
  • JKSHJ Offline
    JKSHJ Offline
    JKSH
    Moderators
    wrote on last edited by
    #4

    Qt supports CBOR too: https://doc.qt.io/qt-5/qtcborcommon.html

    CBOR is like JSON but more flexible (because it supports more types) and faster (because it transmits binary data instead of human-readable text)

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

    B 1 Reply Last reply
    3
    • mrjjM mrjj

      Hi
      Just as a note.
      it's worth considering/mention that most of Qt class can already be serialized with
      QDataStream so if your data structures use Qt types, it's basically just to stream them
      and it's easy to send a QDataStream over QTcpSocket or similar in a platform-independent way.
      ( versioning and endianness support)

      https://doc.qt.io/qt-5/datastreamformat.html#

      B Offline
      B Offline
      bogong
      wrote on last edited by bogong
      #5

      @mrjj There are few questions:

      • QDataStream - Is it ok for cross-platform applications (I mean if I am saving in file for example QVector or QHash data on Andorid device and send it to iOS device will it be equal one another)? There are not linked connection between application instances. It's look like file write by one instance into file and read by another from another whenever it need. Basic idea was to write it in XML or JSON and save it to file.
      • What about long term storing? What about global Qt policy for serialising. What if I store in file and might be reading it in 4 years for example? Is there option to get at least sources for building driver for reading it if something got changed in future in QDataStream. I've been choosing XML or JSON because of very stable format globally.
      mrjjM 1 Reply Last reply
      0
      • B bogong

        @mrjj There are few questions:

        • QDataStream - Is it ok for cross-platform applications (I mean if I am saving in file for example QVector or QHash data on Andorid device and send it to iOS device will it be equal one another)? There are not linked connection between application instances. It's look like file write by one instance into file and read by another from another whenever it need. Basic idea was to write it in XML or JSON and save it to file.
        • What about long term storing? What about global Qt policy for serialising. What if I store in file and might be reading it in 4 years for example? Is there option to get at least sources for building driver for reading it if something got changed in future in QDataStream. I've been choosing XML or JSON because of very stable format globally.
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #6

        @bogong
        Hi
        Yes. should be.
        At least for the normal use cases.
        Also if you use mostly Qt types for the int / floats etc then
        very little hand-holding is needed.

        update:
        Long term. It does support versioning and Qt do not lightly alter its
        interfaces so it would be safe for 4 years+, i would say.
        However, for very long time storage, json (text) beats binary
        as it will always be easier to read in again.

        I would personally go with json in this use case.

        B 1 Reply Last reply
        1
        • mrjjM mrjj

          @bogong
          Hi
          Yes. should be.
          At least for the normal use cases.
          Also if you use mostly Qt types for the int / floats etc then
          very little hand-holding is needed.

          update:
          Long term. It does support versioning and Qt do not lightly alter its
          interfaces so it would be safe for 4 years+, i would say.
          However, for very long time storage, json (text) beats binary
          as it will always be easier to read in again.

          I would personally go with json in this use case.

          B Offline
          B Offline
          bogong
          wrote on last edited by bogong
          #7

          @mrjj Thx for reply I just updated question. And there might be various data types.

          1 Reply Last reply
          0
          • JKSHJ JKSH

            Qt supports CBOR too: https://doc.qt.io/qt-5/qtcborcommon.html

            CBOR is like JSON but more flexible (because it supports more types) and faster (because it transmits binary data instead of human-readable text)

            B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #8

            @jksh Is there any example of using CBOR? Be honest - I've never heard about it ... And the same questions about Long Term Storing, how about it?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bogong
              wrote on last edited by
              #9

              @mrjj @JKSH and others ... Thanks for replies, but never the less ... What about topic of this thread? What is more native JSON and XML?

              mrjjM 1 Reply Last reply
              0
              • B bogong

                @mrjj @JKSH and others ... Thanks for replies, but never the less ... What about topic of this thread? What is more native JSON and XML?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @bogong
                None of them is more native than the other.
                Both is just classes using Qt types.

                B 1 Reply Last reply
                0
                • mrjjM mrjj

                  @bogong
                  None of them is more native than the other.
                  Both is just classes using Qt types.

                  B Offline
                  B Offline
                  bogong
                  wrote on last edited by
                  #11

                  @mrjj Thx

                  mrjjM 1 Reply Last reply
                  0
                  • B bogong

                    @mrjj Thx

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @bogong
                    Just as info.
                    we tested XML / JSON for our project.
                    In most cases, xml is more verbose and we found json
                    generally nicer to work with.
                    Its easy to handwrite some json.
                    xml, not so much.

                    B 1 Reply Last reply
                    2
                    • mrjjM mrjj

                      @bogong
                      Just as info.
                      we tested XML / JSON for our project.
                      In most cases, xml is more verbose and we found json
                      generally nicer to work with.
                      Its easy to handwrite some json.
                      xml, not so much.

                      B Offline
                      B Offline
                      bogong
                      wrote on last edited by bogong
                      #13

                      @mrjj For hand-writing it's mater of experience only. I've started to use XML more than 10 years ago and beside all of it huge experience in HTML/CSS. For me doesn't matter at all which is better for handwriting. BTW - Microsoft *.docx format it's ZIPed XML. And a lot of applications using XML for data exchange. But it's only historically, XML appeared earlier than JSON especially in enterprise applications.

                      mrjjM 1 Reply Last reply
                      0
                      • B bogong

                        @mrjj For hand-writing it's mater of experience only. I've started to use XML more than 10 years ago and beside all of it huge experience in HTML/CSS. For me doesn't matter at all which is better for handwriting. BTW - Microsoft *.docx format it's ZIPed XML. And a lot of applications using XML for data exchange. But it's only historically, XML appeared earlier than JSON especially in enterprise applications.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @bogong
                        ok. also a good xml editor helps with all the end tags.

                        Btw i forgot to ask

                        How much data do you plan to save ?

                        B 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @bogong
                          ok. also a good xml editor helps with all the end tags.

                          Btw i forgot to ask

                          How much data do you plan to save ?

                          B Offline
                          B Offline
                          bogong
                          wrote on last edited by
                          #15

                          @mrjj said in XML vs JS in Qt. What is more "native" for Qt?:

                          How much data do you plan to save ?

                          It's unpredictable and depend on situation. Might be 2 bite might be + 2Gb

                          mrjjM 1 Reply Last reply
                          0
                          • B bogong

                            @mrjj said in XML vs JS in Qt. What is more "native" for Qt?:

                            How much data do you plan to save ?

                            It's unpredictable and depend on situation. Might be 2 bite might be + 2Gb

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @bogong
                            ok.
                            please test with 2GB json/xml before deciding.
                            It might not have acceptable performance for your use case.

                            B 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @bogong
                              ok.
                              please test with 2GB json/xml before deciding.
                              It might not have acceptable performance for your use case.

                              B Offline
                              B Offline
                              bogong
                              wrote on last edited by
                              #17

                              @mrjj sure, I know it - this is the main reason to question about "more native".

                              mrjjM 1 Reply Last reply
                              0
                              • B bogong

                                @mrjj sure, I know it - this is the main reason to question about "more native".

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #18

                                @bogong
                                Well both will be slow with a 2GB file.
                                However, XML has also has
                                https://doc.qt.io/qt-5/qxmlsimplereader.html#details
                                which is a SAX interface that reduces the memory requirements
                                compared to the XML Dom parser / json that will fully
                                populate an internal "tree" of the file.

                                Also, Qt is a framework. Not a language so all its classes are
                                the same level of "native". :)

                                B 1 Reply Last reply
                                1
                                • mrjjM mrjj

                                  @bogong
                                  Well both will be slow with a 2GB file.
                                  However, XML has also has
                                  https://doc.qt.io/qt-5/qxmlsimplereader.html#details
                                  which is a SAX interface that reduces the memory requirements
                                  compared to the XML Dom parser / json that will fully
                                  populate an internal "tree" of the file.

                                  Also, Qt is a framework. Not a language so all its classes are
                                  the same level of "native". :)

                                  B Offline
                                  B Offline
                                  bogong
                                  wrote on last edited by
                                  #19

                                  @mrjj I might be wrong in term "native". I mean what is historically more developed and used solution in Qt.

                                  mrjjM 1 Reply Last reply
                                  0
                                  • B bogong

                                    @mrjj I might be wrong in term "native". I mean what is historically more developed and used solution in Qt.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #20

                                    @bogong
                                    I think they are both equal in that regards.
                                    The XML is older (i think) then JSON but could not find the exact info.
                                    Internally Qt uses binary / DataStreams.

                                    So it seems to save to choose between json/xml based on performance and
                                    memory use concerns + your personal experience with xml.

                                    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