If I am trying to connect to an invalid host, and, after the connection fails, I try to connect to a valid host, the connection still fails.
Qt Code:
  1. void testSoc::test()
  2. {
  3. switch (state)
  4. {
  5. case 0:
  6. case 2:
  7. case 4:
  8. qDebug ("Connecting to a valid host. Should be Ok");
  9. timeout->start(10000);
  10. soc->connectToHost(VALID_HOST, VALID_PORT);
  11. break;
  12. case 1:
  13. qDebug ("Connecting to a invalid port. Should fail");
  14. timeout->start(10000);
  15. soc->connectToHost(VALID_HOST, INVALID_PORT);
  16. break;
  17. case 3:
  18. qDebug ("Connecting to a invalid host. Should fail");
  19. timeout->start(10000);
  20. soc->connectToHost(INVALID_HOST, VALID_PORT);
  21. break;
  22. }
  23. }
  24. void testSoc::checkConnection()
  25. {
  26. timeout->stop();
  27. if (soc->state() == QAbstractSocket::ConnectedState)
  28. {
  29. connected();
  30. } else {
  31. qDebug ("Connection failed");
  32. soc->disconnectFromHost();
  33. if (soc->state() != QAbstractSocket::UnconnectedState)
  34. soc->waitForDisconnected();
  35. soc->close();
  36. //delete soc;
  37. //soc = new QSslSocket;
  38. state ++;
  39. test();
  40. }
  41. }
  42.  
  43. * and of course there is
  44.  
  45. connect (soc, SIGNAL(connected()),
  46. this, SLOT(connected()));
  47. connect (timeout, SIGNAL(timeout()),
  48. this, SLOT(checkConnection()));
To copy to clipboard, switch view to plain text mode 
In this code, all gives the expected results, except for case 4 (including case 2, reconnecting after trying to connect to a valid host, with invalid port)

deleting and re-creating the socket does not help
(using Qt 4.4.3)