Qt: default connection timeout for QTcpSocket
Asked Answered
G

1

6

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?

Gluttony answered 16/8, 2014 at 21:8 Comment(2)
Hi, I don't think there is other solution. You can adjust waitForConnected() but if you don't want this function to be blocking (probably because of GUI or anything), you should use a thread.Thermion
Exactly, because of GUI blocking. I want to have persistent connection for the socket, but I don't know how to do it with threads. If I just move to thread waitForConnected() call, it shows me an output in console 'Cannot create children for a parent that is in a different Thread', but there is no any explicit object creation, just singe waitForConnected.Gluttony
E
9

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.

Eldwen answered 17/8, 2014 at 17:57 Comment(1)
yes, now I implemented it like this with startTimer() of QObject. So I can accept this answer for now.Gluttony

© 2022 - 2024 — McMap. All rights reserved.