(De)serialization QSet with enum using QDataStream

371 Views Asked by At

I use Qt 4.8.7. I have enum Color {red, green, blue} and QSet<Color>. How should I (de)serialize QSet<Color> using QDataStream? Deserialization fails with custom type. Should I manually create serialization (loop over QSet elements) besides deserialization? I mean that internal serialization implementation for QSet in theory can be changed by Qt developers, so I have to write two loops for serialization/deserialization by myself.

1

There are 1 best solutions below

0
ilya On

You can use the following cast for deserialization in order to avoid creating manual loops:

data_stream >> reinterpret_cast<QSet<qint32>&>(color_set2);