#include <QTcpSocket> #include <QDataStream> #include <QByteArray> void sendObjectList(QTcpSocket *socket, const QList<QObject *> &objectList) { QByteArray serializedData; QDataStream out(&serializedData, QIODevice::WriteOnly); out << objectList.size(); // 序列化列表的大小 foreach (QObject *obj, objectList) { out << obj->objectName(); // 假设每个对象都有一个objectName()方法返回其名称 // 这里可以添加其他对象的序列化代码... } socket->write(serializedData); }
##
标签:serializedData,QObject,QTcpSocket,include,QList,out From: https://www.cnblogs.com/herd/p/17935250.html