Solved operator<< has too many parameters
-
I'm trying to override the operator << in order to implement a kind of to string using QDebug and for other usage cases, the problem is that I'm getting an error:
QDataStream& operator<<(QDataStream &stream, const Namer &namer) { return stream << "hi"; } Namer namer; qDebug() << namer;
binary 'operator <<' has too many parameters
binary '<<' : no operator found which takes a left-hand operand of type 'QDebug' (or there is no acceptable conversion) ... -
Hi,
If you would like to send your class through QDebug you need to implement the stream operator for QDebug i.e.:
QDebug operator <<(QDebug dbg, const Name& namer) { dbg << namer.myNiceMethod(); return dbg; }
-
@SGaist It's not only for QDebug, but in cases of strings. I thought that QDataStream would do the job.
-
If you want to support several streams then you have to implement them separately.
As for strings don't you mean QTextStream ?
-
You are right, I checked a few sources and now it's working, thank you.