On Wednesday, 16 May 2018 13:51:39 PDT Jason H wrote: > 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.
QImage has an operator<< for QDataStream that writes PNG content to the stream. However QVariant cannot serialise non-QtCore types to QDataStream. > What's the best way to accomplish this serialization? Manually serialise your QVariantMap: for each value that is an image, call that operator<< directly. That implies manually deserialising too, which means detecting when the stream contains an image. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest