Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.
-
Code as following:
typedef QVector<WellDataAnalyzeInfo> ExpAnalysisResult;//WellDataAnalyzeInfo is a custom struct QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info) { out << info; return out; }
The following code will have the same problem:
QDataStream &operator<<(QDataStream& out, const QVector<int>& info) { out << info; return out; }
But the following is normal:
struct ExpAnalysisResult { QVector<int> ddd; }; QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info) { out << info.ddd; return out; }
-
@crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:
out << info;
What do you think happens here?
-
@crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:
out << info;
What do you think happens here?
@christian-ehrlicher Let each element in the container be written to a file respectively.
-
No, it calls "QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)" - why should it iterate over the container?
-
No, it calls "QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)" - why should it iterate over the container?
@christian-ehrlicher "typedef QVector<WellDataAnalyzeInfo> ExpAnalysisResult;"Because
ExpAnalysisResult
is aQVector<T>
. -
@crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:
Because ExpAnalysisResult is a QVector<T>.
But you give the compiler already an operator for this - namely 'QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)' - so why should another one be used when it finds an exact match for it?
-
Hi,
To add to @Christian-Ehrlicher
@crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:
QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)
{
out << info;
return out;
}The goal of this operator implantation is to serialise the content of your
Analysis::ExpAnalysisResult
object. Just writingout << info
will basically be the operator trying to call itself.There's no automagical way to serialise your object. At some point you have to write down which fields should go in the stream.
-
@crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:
Because ExpAnalysisResult is a QVector<T>.
But you give the compiler already an operator for this - namely 'QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)' - so why should another one be used when it finds an exact match for it?
@christian-ehrlicher @SGaist But the second code snippet is wrong,the third code snippet right. The third code snippet's
info.ddd
as same as the second code snippet's info and the first. AboutWellDataAnalyzeInfo
, I have a alone operator implantation. -
As long as you declare, implement and register the QDataStream operator for your class. You don't have to implement anything special for QVector as it's already handled. You only have to care about your custom type.
-
As long as you declare, implement and register the QDataStream operator for your class. You don't have to implement anything special for QVector as it's already handled. You only have to care about your custom type.