I have faced with a weird problem. When I try to connect, for example to offline server on 127.0.0.1:8080
, socket signal emits "error" as it should but when I connect to 127.0.0.10:8080
or 127.123.4.5:8080
signal does not emit errors. What's the problem and how can I catch failed connection error?
Code 1:
remote_server = new Server(nickname, ip, port); connect(remote_server, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(connection_failed(QAbstractSocket::SocketError))); remote_server->establish_connection();
Code 2:
master_socket = std::move( std::unique_ptr<QTcpSocket>(new QTcpSocket(nullptr)) ); connect(master_socket.get(), SIGNAL(error(QAbstractSocket::SocketError)), SIGNAL(error(QAbstractSocket::SocketError))); master_socket->connectToHost(ip.c_str(), port); master_socket->waitForConnected(2000);