Overloading the QDataStream << and>> operators for a user-defined type

前端 未结 2 532
慢半拍i
慢半拍i 2020-12-11 05:52

I have a an object I\'d like to be able to read and write to/from a QDataStream. The header is as follows:

class Compound
{
public:
    Compound(QString, QPi         


        
2条回答
  •  执笔经年
    2020-12-11 06:02

    I think you've answered your own question! The stream operator

    QDataStream& operator<<( QDataStream&, const Compound& )
    

    will work fine. In the implementation you just use the existing stream operators on QDataStream to serialise the individual bits of your Compound. Some Qt classes define non-member QDataStream operators too. QString is one and so is QList so it looks like you're sorted!

提交回复
热议问题