1

I want to detect the state of network. I found two ways to look for the internet connection in bb 10.2 but no one seems to be working:

1: It always return "QNetworkAccessManager::UnknownAccessibility"

QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
networkAccessManager->networkAccessible();

2: It always return true

QNetworkConfigurationManager *manager = new QNetworkConfigurationManager();
bool res = QObject::connect(manager,
                SIGNAL(onlineStateChanged(bool)),
                this,
                SLOT(onOnlineStateChanged(bool)));
Q_ASSERT(res);

Could anybody help me on this?

Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57
anam
  • 61
  • 1
  • 5
  • 1
    Regarding the second one: `QObject::connect` return `true` if the connection has been successful, `false` otherwise. You can try to log the state in your `onOnlineStateChanged` slot and turn on/off airplane mode to see if it's logged. – Marc Plano-Lesay Sep 25 '14 at 15:28
  • Second one seems to be working on device but not on the simulator. – anam Sep 30 '14 at 07:03
  • But this also doesn't work if we start app in offline mode. Any suggestions? – anam Sep 30 '14 at 07:54

1 Answers1

0

A solution is to use QNetworkConfigurationManager::isOnline().

QNetworkConfigurationManager *manager = new QNetworkConfigurationManager();
Q_ASSERT(manager->isOnline());
Marc Plano-Lesay
  • 6,808
  • 10
  • 44
  • 75
  • Thanks Kernald for your response. I'm still not able to detect network using above code. Are there any settings or configurations that we need to update in app? My app has "Internet" permissions enabled btw. – anam Sep 30 '14 at 06:51