QTcpSocket发送存储QObject的QList
#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); }
##
QQ 3087438119