[Interest] QDatastream, QMap, QImage serialization
Jérôme Godbout
godboutj at amotus.ca
Wed May 16 23:38:08 CEST 2018
You will need to provide your own
QDataStream& operator<<(QDataStream& ds, const QImage& img)
{
ds << img.height() << img.width() << img.format() << img.data()
}
and
QDataStream& operator>>(QDataStream& ds, QImage& img)
{
int height;
ds >> height;
img.setHeight(height);
...
}
Then you might want to serialize the QByteArray and image format or anything required to rebuild the image from the data.
http://doc.qt.io/qt-5/qimage.html#fromData-1
I have check in depth the needed data but you get the idea
________________________________
From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> on behalf of Jason H <jhihn at gmx.com>
Sent: May 16, 2018 4:51 PM
To: interestqt-project.org
Subject: [Interest] QDatastream, QMap, QImage serialization
I'm trying to write a GUI utility to provide a simple UI. I'm wanting a no-frills database of several Qt types, and I'm trying to use QVariantMap for that. It's going well except that QImages aren't being serialized correctly. Yes, I know there is a QVariant limitation with "GUI types" ( http://doc.qt.io/qt-5/qvariant.html#a-note-on-gui-types ) however QImage has an operator QVariant(). I was expecting to see pixel data get stored in the file, but it's just being stored as an empty QString. So it seems that QDataStream can't serialize a QImage? I know that's not true, so it looks like QDataStream can't serialize a QVariant that is a QImage. I think that's what I'm running into. I would expect some QByteArray fall-back, but the bytes aren't making it to disk. It would be ok for me if I had to manually convert the image later from an opaque byte array, so long as it was written and read properly.
What's the best way to accomplish this serialization?
Many thanks!
_______________________________________________
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/20180516/195785dc/attachment.html>
More information about the Interest
mailing list