Qt: default connection timeout for QTcpSocket

user3948829 picture user3948829 · Aug 16, 2014 · Viewed 11.6k times · Source

Please advise how can I setup default connection timeout without using blocking waitForConnected() method? I noticed that socket emit error signal (QAbstractSocket::SocketTimeoutError) after about 60 seconds that I can handle as a timeout, but can this timeout be adjusted?

Answer

hyde picture hyde · Aug 17, 2014

You could use a QTimer:

When developing, make sure to connect the stateChanged(...) and error(...) signals at least to debug slots, which just print the arguments. That way you will see when something happens in a way you did not expect.