CactusPie
20th February 2013, 00:17
I am having an odd problem with QTcpSocket error signal. I define new socket like this:
socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(ReceivedPacket()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(connectionError(QAbstractSocket::SocketError) ));
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;
}
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!
socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(ReceivedPacket()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(connectionError(QAbstractSocket::SocketError) ));
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;
}
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!