There are two ways that I can think of for checking if a TCP socket times out in Qt. You can either use `waitForConnected` or a `QTimer`. The Qt 5.14 documentation noted that the `waitForConnected` call may randomly fail in Windows.
Here is some shared code for both examples
```c++
QTcpSocket *socket = new QTcpSocket(this);
quint16 listenPort = 4444;
int timeout = 1000; // Units: milliseconds
QHostAddress destination("192.168.0.2");
```
## `waitForDisconnected`
Let's say that we have a `QTcpScoket` pointer named `socket`.
```c++
socket->connectToHost(destination, listenPort);
if (!socket->waitForConnected(timeout)) {
qDebug("Connection Timed Out.");
}
```
Notes:
-`waitForConnected` is a blocking call
- This does not account for the host lookup call.
## `QTimer`
This method requires a little more setup. Let's assume we have a class named `Test` that inherits `QObject`.