XML vs JS in Qt. What is more "native" for Qt?
-
Hi,
Qt has classes for both.
The questions are rather:
- what do you want to exchange ?
- how do you want to exchange it ?
- is it web related ?
-
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) -
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)
-
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)@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.
-
@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.
@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.
-
@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.
-
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)
-
-
@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.@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.
-
@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.
-
@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 ?
-
@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
-
@bogong
ok.
please test with 2GB json/xml before deciding.
It might not have acceptable performance for your use case. -
@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". :) -
@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". :) -
@mrjj I might be wrong in term "native". I mean what is historically more developed and used solution in Qt.
@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.