Reputation: 2225
I have overloaded '<<' operator for MyClass.
friend std::ostream& operator << (std::ostream& out, const MyClass& Obj);
Now I want to convert std::ostream to QDataStream rather than converting MyClass to QDataStream.
friend QDataStream operator << (QDataStream& out, std:ostream&);
Something like this. Your help will be appreciated.
Upvotes: 2
Views: 2160
Reputation: 8303
You can't just convert one into the other. But you can use QBuffer
as a workaround. It is a QIODevice
, so you can create a QDataStream
from it. When done writing your data, get the QByteArray
from the buffer and use its data to write to your std::ostream
.
Upvotes: 6