Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, December 2007
QTcpSocket disconnected() behaviour question


Message 1 in thread

Hi,

I have a QTcpSocket in my application.  I am implementing a client
application which must retry connecting to a server indefinitely, but with
a capped exponential backoff until the application terminates (private
network, private server).

My question is:

If I call QTcpSocket->connectToHost(host, port) but the socket fails to
connect (timeout, error, whatever) is disconnected() called as well as
error()?  My guess is no, because the socket was never "connected", but I
am not sure because the documentation on error() and disconnected() is
sparse.

I haven't the time to build a thorough test for this. I'm hoping that
someone will know the answer here so I can design the behaviour of my
application sensibly.

Cheers,
A

--
 [ signature omitted ] 

Message 2 in thread

Adam Hawes wrote:
>If I call QTcpSocket->connectToHost(host, port) but the socket fails to
>connect (timeout, error, whatever) is disconnected() called as well as
>error()?  My guess is no, because the socket was never "connected", but
> I am not sure because the documentation on error() and disconnected()
> is sparse.

disconnected() can only be emitted after connected() was emitted.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

> disconnected() can only be emitted after connected() was emitted.
 
Thanks, that's what I thought but I hadn't the time to write a suite of
tests to verify all the possible non-connection cases.

One case I have run into is when a socket is in the connecting state (remote
host is not responding at all) and you call QCoreApplication::quit() you
see the disconnected signal from the socket; hence my confusion.

Regards,
Adam

--
 [ signature omitted ]