1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include "gps.h"
#include "ui_appgest.h"
#include "appgest.h"
GPS::GPS(QObject *parent) :
QObject(parent)
{
appGest *tmp = qobject_cast<appGest *>(parent);
this->udpSocket = NULL ;
}
void GPS::initSocket(QHostAddress pAdress,int pPort)
{
this->udpSocket = new QUdpSocket(this);
this->udpSocket->bind(pAdress, pPort);
connect(this->udpSocket, SIGNAL(readyRead()),
this, SLOT(readPendingDatagrams()));
}
void GPS::readPendingDatagrams()
{
QString message ;
appGest *Ihm = qobject_cast<appGest *>(parent()) ;
while (this->udpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(this->udpSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
this->udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
message = datagram ;
emit Ihm->updateGps(message) ;
}
} |