socket->connectToHost(ip,port);QDateTime finishTime = QDateTime::currentDateTime();QTime time;time.start();LockUserInterface();while ( ( time.elapsed() < timeout ) && ( ( socket->state() = QSocket::HostLookup ) || ( socket->state() = QSocket::Connecting ){ QApplication::processEvents( 100 );}UnlockUserInterface();if ( socket->state() = QSocket::Connected ){ // …}else{ socket->close(); // …}