Results 1 to 3 of 3

Thread: How to destroy a UdpSocket completely

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to destroy a UdpSocket completely

    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.

    Qt Code:
    1. void GPSNetwork::startReceive()
    2. {
    3. stop = false;
    4. udpSocketRead = new QUdpSocket();
    5. udpSocketRead->bind(45454);
    6. connect(udpSocketRead, SIGNAL(readyRead()),this, SLOT(start()));
    7. }
    8.  
    9. void GPSNetwork::run()
    10. {
    11. while ((udpSocketRead->hasPendingDatagrams())&&(stop==false))
    12. {
    13. QByteArray datagram;
    14. datagram.resize(udpSocketRead->pendingDatagramSize());
    15. udpSocketRead->readDatagram(datagram.data(),datagram.size());
    16. if (datagram.size()!=0)
    17. emit msg(datagram.data());
    18. }
    19. }
    20.  
    21. void GPSNetwork::stopReceiveFromNetwork()
    22. {
    23. stop=true;
    24. disconnect(udpSocketRead, 0,this,0);
    25. delete udpSocketRead;
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 21st October 2006 at 08:17. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 24th June 2006, 20:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.