[Interest] Serializing QSensorReading derived classes

Jérôme Godbout godboutj at amotus.ca
Wed Feb 21 15:50:39 CET 2018


you might want to add definition for you own data type:

QDataStream &operator<<(QDataStream &out, const MyCustomType &var);
QDataStream &operator>>(QDataStream &in, MyCustomType &var);

This should be enough to make this work. You probably will have to serialize the mode as int and the x/y/z as qreal value


out << (int)var.mode() << var.reading().x() << var.reading().y() << var.reading().z();


and do the inverse when reading into local var, then call the proper constuctor/setter


qreal x, y, z;

int mode;

in >> mode >> x >> y >> z;

var.setAccelerationMode(mode);

var.reading().setX(x);

var.reading().setY(y);

var.reading().setZ(z);

________________________________
From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> on behalf of Jason H <jhihn at 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 at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180221/600b267c/attachment.html>


More information about the Interest mailing list