[Solved] Understanding QUdpSocket - deleting
-
"QUdpSocket destructor":http://qt-project.org/doc/qt-5/qudpsocket.html#dtor.QUdpSocket automaticaly closes the connection.
bq. QUdpSocket::~QUdpSocket() [virtual]
Destroys the socket, closing the connection if necessary.Have you tried to @delete lola_socket;@
-
What Jena43 said will do it, and you can specifically do it without destroying your object with:
@
lola_socket->disconnectFromHost();
@ -
As a side note sometimes when I have a crash using delete directly on Qt objects it has to do with outstanding signals that haven't been handled by that object yet.
In those situations you can always do
@
lola_socket->deleteLater()
@and the next time the exec loop comes around it will clean up that object once everything it had outstanding has been processed by the event loop.
Which is why it works now but didn't before. Different things in the code led to different outstanding signals which you didn't have this time around.
Oh, and once you call deleteLater() assume that object and it's pointers are dead and don't use them again, even though they may remain valid for a little bit. After a deleteLater() I tend to set my pointers to 0 just to be sure that if I accidentally use them it's easy to catch.
-
Once you call deleteLater() you can act as if it had been deleted. You can create a new one, even over the same pointer.
Even if it was still connected by the time your new socket went to connect the event loop would have cleaned up the old one.
So basically, you can think it is deleted just as if you had done delete ptr; on it.