[英]std::ostream to QDataStream
I have overloaded '<<' operator for MyClass. 我为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. 现在,我想将std :: ostream转换为QDataStream,而不是将MyClass转换为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. 但是您可以使用
QBuffer
作为解决方法。 It is a QIODevice
, so you can create a QDataStream
from it. 这是一个
QIODevice
,因此您可以从中创建一个QDataStream
。 When done writing your data, get the QByteArray
from the buffer and use its data to write to your std::ostream
. 完成写入数据后,从缓冲区获取
QByteArray
并使用其数据写入std::ostream
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.