首页 > 代码库 > QDataStream和QByteArray

QDataStream和QByteArray

一个写操作可以参考:

QDataStream &operator >>(QDataStream &in, SerializedMessage &message)
{
   qint32 type;
  qint32 dataLength;
  QByteArray dataArray;
  in >> type >> dataLength;
  dataArray.resize(dataLength);  // <-- You need to add this line.
  int bytesRead = in.readRawData(dataArray.data(), dataLength);
  // Rest of function goes here.
}

 

QDataStream和QByteArray