我想發送和接收使用QTCPSocket的結構。如何通過QTcpSocket接收結構?
該系統確實有一箇中央套接字服務器和大量的Qt客戶端應用程序。 每個客戶端都會發送一個由中心套接字服務器廣播給其餘結構的結構。
Connector
延伸QTcpSocket
這是我的用於連接
void Connector::Open(QString address, int port) // It works!
{
connectToHost(address, port);
this->onWaiting();
connect(this, SIGNAL(connected()), this, SLOT(connected()));
connect(this, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(this, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
}
方法這是我的用於發送數據
void Connector::SendData(const void* data,qint64 len) // It works!
{
writeData((char*)data,len);
waitForBytesWritten();
}
這是用於接收
void Connector::readyRead() // Don't work
{
Information n; //My struct
memcpy(&n, data.data(), data.size());
onInformationReceived(n);
}
方法
但收到的信息始終無效。那是對的嗎?
你送什麼樣的數據? – purplepsycho