I would like to send and receive a structure using QTCPSocket.
the System does have a central Socket Server and a lot of Qt Client Applications. Each client sends a struct which is broadcast to the rest by the central socket server.
Connector
extends QTcpSocket
this is my method for connecting
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)));
}
This is my method for sending data
void Connector::SendData(const void* data,qint64 len) // It works!
{
writeData((char*)data,len);
waitForBytesWritten();
}
this is for receiving
void Connector::readyRead() // Don't work
{
Information n; //My struct
memcpy(&n, data.data(), data.size());
onInformationReceived(n);
}
But the information received is always invalid. Is that correct?