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...@qt-project.org> on behalf 
of Jason H <jh...@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@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