Verfiying the network connection using Qt 4.4

后端 未结 3 1972
后悔当初
后悔当初 2020-12-17 01:34

I have an application which runs a tool that requires network connection. Now my aim is to check whether the user has a network connection, if he don\'t have one, i can stra

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 02:22

    I assume that by "network connection" you mean "internet connection", i.e. you don't care about LAN or some ad-hoc networks between your desktop and mobile.

    The easiest way is just to connect to the internet service your application needs and let OS handle the network request. If you get the reply, there is a connection, if the request times out, there is no connection.

    You can check state of network interface through QNetworkInterface::flags(), but this doesn't give you the information about the network the interface is connected to: the interface might be up, but connected only to LAN without internet access.

提交回复
热议问题