PDA

View Full Version : QTcpSocket 'connected()' signal issue



Vladimir_
24th September 2014, 16:04
Hello,

I wanted to do an action when an incoming connection to the server is established from a client.

i wrote this line :

connect(socket,SIGNAL(connected()), this, SLOT(connected()));

while "socket" is is a pointer to QTcpSocket :

socket = new QTcpSocket;

But the statement doesn't invoke te SLOT "connected()" .

but when I write the following code:

connect(socket,SIGNAL(disconnected()), this, SLOT(connected()));

The SLOT "connected()" will be called when the Client is exited.

The issue:
I need to invoke the SLOT when an incoming connection established from a client.

Thanks.

anda_skoa
24th September 2014, 16:44
There is some inconsistency in your posting:


I wanted to do an action when an incoming connection to the server is established from a client.

This sounds like you are writing server code.



while "socket" is is a pointer to QTcpSocket :

socket = new QTcpSocket;

while this is clearly client code.

For a client the connect should work, i.e. the slot should be invoked when the socket establishes a connection to the server.
For a server, the client is already connected (it has connected to the server after all), so the socket is already in "connection established" state.

Cheers,
_

Vladimir_
24th September 2014, 16:52
lol i was using a QTcpSocket in the server...

So what's the SIGNAL i have to make to get the incoming connection ?? "using QTcpServer"

thanx

ChrisW67
24th September 2014, 21:16
QTcpServer... the answer is in the first few sentences of the detailed description. Try the Fortune Server Example, also linked from the detailed description section, for a complete worked example.