Detecting change of internet connection
-
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...bohEDIT: 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 -
Hi,
Which version of Qt are you using ?
On what platforms ? -
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?
-
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?