I am having an odd problem with QTcpSocket error signal. I define new socket like this:
connect(socket, SIGNAL(readyRead()), this, SLOT(ReceivedPacket()));
socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(ReceivedPacket()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(connectionError(QAbstractSocket::SocketError)));
To copy to clipboard, switch view to plain text mode
And everything works fine, until an error appears. Let's say I'm gonna try to connect to a host that doesn't accept connections on the port I'm trying to connect to. Error singal will be emitted, and after about 1 second there will be another one. Inside the error slot I have the following piece of code:
if(socket)
{
delete socket;
socket = NULL;
}
if(socket)
{
delete socket;
socket = NULL;
}
To copy to clipboard, switch view to plain text mode
But it still causes server crashes (due to a double free) and the error message is displayed twice.
The entire code is a little bit longer, but it is available here: http://pastebin.com/9CrdK95i
How can I prevent the error signal from being emitted/captured twice?
Could someone please help me?
Thank you in advance!
Bookmarks