Noor Nawaz
Noor Nawaz

Reputation: 2225

std::ostream to QDataStream

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

Answers (1)

Guilherme Bernal
Guilherme Bernal

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

Related Questions