标签:
QT自带的QDataStream只能传递它自己要求的数据类型。但是我们可以自己重载QDataStream& operator<<()和QDataStream& operator>>();
mydatastream.h
1 #ifndef MYDATASTREAM_H 2 #define MYDATASTREAM_H 3 4 #include <QDataStream> 5 6 struct UserInfor{ 7 QString id; 8 QString state; 9 QString ip; 10 QString port; 11 QString nickName; 12 QByteArray headPhoto; 13 QString discription; 14 }; 15 16 inline QDataStream& operator<<(QDataStream& out, const UserInfor& userInfor) 17 { 18 out<<userInfor.id<<userInfor.state<<userInfor.ip<<userInfor.port<< 19 userInfor.nickName<<userInfor.headPhoto<<userInfor.discription; 20 return out; 21 } 22 23 inline QDataStream& operator>>(QDataStream& in,UserInfor& userInfor) 24 { 25 in>>userInfor.id>>userInfor.state>>userInfor.ip>>userInfor.port>>userInfor.nickName 26 >>userInfor.headPhoto>>userInfor.discription; 27 return in; 28 } 29 30 #endif // MYDATASTREAM_H
标签:
原文地址:http://www.cnblogs.com/jasonkent27/p/4190725.html