I create a UdpSocket and work well, then destroy it.
However, when i create it again, my program does not work.
Please give me some advice.
void GPSNetwork::startReceive()
{
stop = false;
udpSocketRead->bind(45454);
connect(udpSocketRead, SIGNAL(readyRead()),this, SLOT(start()));
}
void GPSNetwork::run()
{
while ((udpSocketRead->hasPendingDatagrams())&&(stop==false))
{
datagram.resize(udpSocketRead->pendingDatagramSize());
udpSocketRead->readDatagram(datagram.data(),datagram.size());
if (datagram.size()!=0)
emit msg(datagram.data());
}
}
void GPSNetwork::stopReceiveFromNetwork()
{
stop=true;
disconnect(udpSocketRead, 0,this,0);
delete udpSocketRead;
}
void GPSNetwork::startReceive()
{
stop = false;
udpSocketRead = new QUdpSocket();
udpSocketRead->bind(45454);
connect(udpSocketRead, SIGNAL(readyRead()),this, SLOT(start()));
}
void GPSNetwork::run()
{
while ((udpSocketRead->hasPendingDatagrams())&&(stop==false))
{
QByteArray datagram;
datagram.resize(udpSocketRead->pendingDatagramSize());
udpSocketRead->readDatagram(datagram.data(),datagram.size());
if (datagram.size()!=0)
emit msg(datagram.data());
}
}
void GPSNetwork::stopReceiveFromNetwork()
{
stop=true;
disconnect(udpSocketRead, 0,this,0);
delete udpSocketRead;
}
To copy to clipboard, switch view to plain text mode
Bookmarks