I try to take values from a Socket I'll receive from another program. Normally, the socket is divided into segments of 4 bytes, except particular case of 20 bytes data.
I know the method for read the signal, using this thread : How to receive proper UDP packet in QT?
So here the example I take from this topic:
while (socket->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(socket->pendingDatagramSize());
socket->readDatagram(datagram.data(),datagram.size(),&sender,&port);
qDebug() <<"Message From :: " << sender.toString();
qDebug() <<"Port From :: "<< port;
qDebug() <<"Message :: " << datagram;
}
How and what to segment after that ?
Is that "datagram.data()" ? Just "datagram" ? Using substr like "QByteArray firstdata = (datagram.data()).substr(0,4)" don't work...
Is there another function ?
By example, for a datagram like (in Hex) : 00 00 00 02 00 00 00 01 00 00 (...) 43 46 , I want to split it like :
uint32_t a = (00 00 00 02);
uint32_t b = (00 00 00 01) ;
char c = (00 00 00 (...) 46);
Thank you !