[Solved]How to check socket connect to host
-
Hi,
If the connection succeeds "connected":https://qt-project.org/doc/qt-5/qabstractsocket.html#connected signal is emitted.
You can connect this signal to your slot. -
Of course the statement below is always true:
@if(socket->state() == QAbstractSocket::ConnectedState || QAbstractSocket::ConnectingState)
@as QAbstractSocket::ConnectingState is certainly greater then zero.
You need to change the statement to
@if((socket->state() == QAbstractSocket::ConnectedState) ||
(socket->state() == QAbstractSocket::ConnectingState))@
-
Thanks all for the reply..
First of all i am checking socket is connected using
if (socket->state() == QAbstractSocket::UnconnectedState)
it is working fine, then i add
socket->connectToHost(server->text(), port->value());
after this i want to know is it conncet or not??
Moreover, I try to use this
if (socket->state() == QAbstractSocket::connectedState)
But it is not working?
Could you please guide me?
-
Did you try connecting to the "connected":https://qt-project.org/doc/qt-5/qabstractsocket.html#connected signal ?
-
Look at the example in the documentation (fortune client)
"http://qt-project.org/doc/qt-5/qtnetwork-fortuneclient-example.html":http://qt-project.org/doc/qt-5/qtnetwork-fortuneclient-example.html.If you still have trouble post your code
-
If your problem is solved then please prepend your title as <solved>.