Serialization two vectors that are in a structure
Hi,
How do I overload the << >> functions to be able to serialize the vectors?
The struct is the next one:
struct realDataValue{
QVector<double> xValueVector;
QVector<double> yValueVector;
bool operator==(const realDataValue &other) const
{
return xValueVector==other.xValueVector && yValueVector==other.yValueVector;
}
};
Thanks a lot.
Re: Serialization two vectors that are in a structure
QVector<T> already has an implementation for serialization to a QDataStream via non-menber functions operator>> and operator<<. Do you need to serialize to some different kind of stream?
Re: Serialization two vectors that are in a structure
Thanks for answering
I need serialization of variables type QString and double.
I have already used the following code
inline QDataStream & operator << (QDataStream & outStream, const realDataValue & mRealDataValue)
{
return outStream << mRealDataValue.xValueVector << mRealDataValue.yValueVector;
}
but when reading a QVector <QString> or QVector <double> of a stream it sends me an error, "invalid operands to binary expression (QDataStream and const QVector <QString>)
inline QDataStream & operator >> (QDataStream & outStream, const realDataValue & mRealDataValue)
{
return outStream >> mRealDataValue.xValueVector >> mRealDataValue.yValueVector;
}
thanks
Re: Serialization two vectors that are in a structure
Quote:
but when reading a QVector <QString> or QVector <double> of a stream it sends me an error
because in your operator>> method, you have declared the realDataValue argument as "const". You can't modify a const reference.