Unsolved Detecting change of internet connection
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?
Which version of Qt are you using ?
On what platforms ?
@SGaist Hello...android and Qt 5.11.2
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?
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.