hi ,folks,i have a problem in qbytearray to float array,i received float array in udp,but return value is 0,what's wrong with me?can u help me?tks.i have searched in google.
the sender program is write by labwindows cvi.
cvi code:
float AIdat[344];
UDPWrite(writerChannel, AI_PORT, MULTICAST_ADDRESS, AIdat, sizeof(AIdat));
float AIdat[344];
UDPWrite(writerChannel, AI_PORT, MULTICAST_ADDRESS, AIdat, sizeof(AIdat));
To copy to clipboard, switch view to plain text mode
qt code:
const udpsize=1376;
void Widget::processPendingDatagrams()
{
qint16 packetsize;
while (udpSocket->hasPendingDatagrams()) {
packetsize=udpSocket->pendingDatagramSize();
ba.resize(packetsize);
udpSocket->readDatagram(ba.data(), ba.size());
if (packetsize!=udpsize)
{
return;
}
// bool ok;
// ba = QByteArray::number(ba.toLongLong(&ok,16),2);
float firstdat;
datin>>firstdat; //first float data
if (!datin.status())
{
qDebug()<<"ok" ;
}
qDebug()<<firstdat; //it return 0 or inf;
}
}
const udpsize=1376;
void Widget::processPendingDatagrams()
{
qint16 packetsize;
while (udpSocket->hasPendingDatagrams()) {
QByteArray ba;
packetsize=udpSocket->pendingDatagramSize();
ba.resize(packetsize);
udpSocket->readDatagram(ba.data(), ba.size());
if (packetsize!=udpsize)
{
return;
}
// bool ok;
// ba = QByteArray::number(ba.toLongLong(&ok,16),2);
QDataStream datin(&ba,QIODevice::ReadOnly);
float firstdat;
datin>>firstdat; //first float data
if (!datin.status())
{
qDebug()<<"ok" ;
}
qDebug()<<firstdat; //it return 0 or inf;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks