The serialization assume you known what type you are reading. If you have a dynamic structure, you will need to add some info about the next data coming (type or something). DataStream convert the object minimal data to byte and no information about what those byte represent. You might have the type intelace inside the datastream or you might do an header that tell the sequence of object (I personnaly would prefer the 2nd choice since you can optimize the sequence with a commun series). Ex:
type bytes series [1,2,354] where those type could be QVariant basic type or user defined type that you could make a switch (could represent a single Type of a series of chained types ex: 354 --> [QString, int, QVector3D, MyCustomType]. This way you could reduce the type bytes series length and could add the real data validation with data length and checksum if ever needed. As for QDataStream it can serialize a lot of data type of of the box, but you might need to add some operator to serialize some types. Here's the list of supported data types: http://doc.qt.io/qt-5/datastreamformat.html You might need to extend the support to the QAcceleromterReading and QAltimeterReading to do you own data reading and call the constructor with the proper deserialized data. ________________________________ From: Interest <interest-bounces+godboutj=amotus...@qt-project.org> on behalf of Jason H <jh...@gmx.com> Sent: Wednesday, February 21, 2018 1:05:35 AM To: interestqt-project.org Subject: [Interest] Serializing QSensorReading derived classes I'd like to serialize these values. QAcceleromterReading has x,y,z properties, but to serialize this one, the accelerometer mode should also be included. But aside from that, I'm not clear on what I need to do. There's adding the QDataStream << >> (QDataScream stream, QSensorReading reading) operators. But that won't allow me to know what I'm reading, so I need to add a byte to know what I'm deserializing, which means I should really do it via QVariant in the QMetaType system. qRegisterMetaType() and DECLARE_META_TYPE(). However, when I do this I get: qmetatype.h:766: error: call to implicitly-deleted copy constructor of 'QAltimeterReading' return new (where) T(*static_cast<const T*>(t)); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ for each of the types. What can I do to get this to work without having to write (derive) my own classes? I'm also wondering why this isn't supported already? _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest