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...@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

Reply via email to