PDA

View Full Version : connected() signal is lost on QTcpSocket



nuliknol
10th August 2016, 01:23
Hi,

I am using QTcpSocket object to create a socket and after that I use it to connect to a server. The problem I have is that the second time I connect to the server, I do not receive the "connected()" signal. The signal never comes. In my application every time I send something form the client to the server I disconnect. The work around I did quickly is to create the socket object again every time I need to connect, but this is obviously not good. So my question is this:

If a QTcpSocket was already used (have been connected and discconected already) do I have to connect the "connected()" signal again on it or does it permanently works from the first time??
I mean, do I have to execute this code:


connect(sock, SIGNAL(connected()), this, SLOT(client_connected()));
every time I disconnect , so next time I connect it will be triggered again ?

TIA
Nulik

jefftee
10th August 2016, 05:03
Is your QTcpSocket destroyed after you disconnect? I believe any connected signals will be removed when the destructor is called.

anda_skoa
10th August 2016, 10:27
If a QTcpSocket was already used (have been connected and discconected already) do I have to connect the "connected()" signal again on it or does it permanently works from the first time??

signal/slot connections are permanent as long as both objects exist.
They can be explicitly disconnected and are automatically disconnected if either object is deleted.

Cheers,
_