How to check Ethernet port connection status in Qt?
-
Hi everyone,
I am new to Qt .Actually, i want to check Whether the Ethernet is connected or not through qt application.
For Example: when the Data is transfer from source to Destination through Ethernet. if i suddenly, remove the Ethernet cable my Qt application has to give some pop-up message like "the connection is unavailable". Is there any way to find this one? Finally,Sorry for my English. -
How are you transferring the data ? Are you using the sockets ? If ethernet is removed, you will get the connection reset error at socket end point. Based on this you should be able to show some error message to user.
-
@dheerendra Thankyou for your reply sir. Yes i created sockets . Actually i'm using udp communication. my exact doubt is while data is transferring through Ethernet . if i suddenly remove the ethernet cable . Which signal will generate in Qt?
-
If it UDP, it difficult. Error can happen only if you try to write a data. Try catching the error() or disconnected() signals from UDP.
-
@dheerendra I tried sir. when i send data using QUdpSocket::writedatagram function even ethernet connection is not there also this function(writedatagram) return success only.
-
As I said earlier, very difficult to get the status ethernet using UDP. UDP is fire & forget protocol. You need to build your own mechanism to monitor the status. It could be simple TCP connection to see if the connection alive with remote server. If not you need to get the interfaces status periodically through QNetworkInterface & check if the interface is up. You can use QNetworkInterface::flags() & QNetworkInterface::IsUp to check the status.