Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Appropriate API for detecting network status change



  • Trying to figure out how to get notified of Internet availability after disconnection. According to the documentation there are multiple potential APIs:

    1. QNetworkSession::stateChanged()
    2. QNetworkAccessManager::networkAccessibleChanged()
    3. QNetworkConfigurationManager::onlineStateChanged()

    onlineStateChanged, basically just checks all network interfaces if they are Up or not and if any of them is working, then it returns true. The problem is that if wifi/lan is connected but ISP/internet is down OR wifi/lan is disconnected but a virtual interface (typically created by VMs) is active. In these cases it still returns true/online.

    I'm not 100% sure about 1 & 2. Can anyone briefly explain the differences between these APIs and use cases? Is there an API that notifies when Internet becomes (un)available?


  • Moderators

    @Taytoo said in Appropriate API for detecting network status change:

    Is there an API that notifies when Internet becomes (un)available?

    There is no such API in Qt. If you want to check, periodically ping some well-known host (your server or google.com etc.). There are some native APIs for detecting Internet access, for example on Android. But there is no common API for all systems (at least in Qt).


Log in to reply