Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Detecting change of internet connection
QtWS25 Last Chance

Detecting change of internet connection

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlterX
    wrote on last edited by AlterX
    #1

    Hello guys,
    I need to detect on smartphones (right now android) when a new connection is available or down (e.g. when 3G goes to Wifi and vice versa). In the past I used QNetworkSession that after Nokia owning seems to not work anymore with mobile but with desktop...
    So yesterday I found another way, that is using QNetworkConfigurationManager::onlineStateChanged(bool isOnline).
    This seems to work quite well when system switches from WIFI to 3G, but when the 3G is going to WIFI, the object doesn't trigger any notification and thus I cannot reconnect using the new IP given.
    In the past I opened a bug for QNetworkSession but they said it is working...boh

    EDIT: what I have understood right now is that onlineStateChange works only when the interface is switched off; this means when 3g comes over when I switch off the wifi and when I set offline mode and then switch on the wifi). For the automatic switch, when for example the connected wifi goes out of range thus 3G automatically takes over and vice-versa there is no way that I found out!
    I tried to connect to as much available as possible without receiving any alert from Qt:

    //your code here
        connect(&netConfigManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Communicator::networkOnlineChanged);
        connect(&netConfigManager, &QNetworkConfigurationManager::configurationChanged, this, &Communicator::configurationChanged);
        netSession = new QNetworkSession(netConfigManager.defaultConfiguration(), this);
        connect(netSession, &QNetworkSession::stateChanged, this, &Communicator::networkStateChanged);
        connect(netSession, &QNetworkSession::newConfigurationActivated, this, &Communicator::newConfigurationActivated);
    

    Can soeone help me?
    thanks
    Gianni

    Qt Ambassador
    Real-time cooperative teams: http://www.softairrealfight.net
    Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

    https://codereview.qt-project.org/...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      On what platforms ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?
        On what platforms ?

        A Offline
        A Offline
        AlterX
        wrote on last edited by AlterX
        #3

        @SGaist Hello...android and Qt 5.11.2

        Qt Ambassador
        Real-time cooperative teams: http://www.softairrealfight.net
        Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

        https://codereview.qt-project.org/...

        aha_1980A 1 Reply Last reply
        0
        • A AlterX

          @SGaist Hello...android and Qt 5.11.2

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @AlterX,

          connect(&netConfigManager, &QNetworkConfigurationManager::onlineStateChanged

          Hmm, is netConfigManager a stack variable that goes out of scope?

          Also, is the event loop running?

          From this snippet it's hard to tell, can you upload a minimal project somewhere?

          Qt has to stay free or it will die.

          A 1 Reply Last reply
          1
          • aha_1980A aha_1980

            Hi @AlterX,

            connect(&netConfigManager, &QNetworkConfigurationManager::onlineStateChanged

            Hmm, is netConfigManager a stack variable that goes out of scope?

            Also, is the event loop running?

            From this snippet it's hard to tell, can you upload a minimal project somewhere?

            A Offline
            A Offline
            AlterX
            wrote on last edited by
            #5

            @aha_1980 Hi,
            all the required objects are global and the app is working thus the main loop is not blocked. I will try to isolate the code and create a small app.

            Thanks
            Gianni

            Qt Ambassador
            Real-time cooperative teams: http://www.softairrealfight.net
            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

            https://codereview.qt-project.org/...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved