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.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.