简体   繁体   中英

Network connectivity check in blackberry cascades 10

I'm trying to perform a network connectivity check whenever user opens the app or whenever app comes in foreground. Below is the sample code

void ApplicationUI::onFullscreen()
{
    qDebug()<<"Application has entered foreground";
    QNetworkConfigurationManager mgr;
    QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);
    if (activeConfigs.count() > 0)
    {
           qDebug()<<"Has Internet connection";
       }
       else
       {
           qDebug()<<"No Internet connection";
       }

}

This always prints Has Internet connection even when the network connection is off. Any ideas?

You can use QNetworkConfigurationManager.isOnline().

QNetworkConfigurationManager mgr;
mgr.isOnline();

If you want to get notified about changes of the online state then you also can connect to the QNetworkConfigurationManager::onlineStateChanged(bool isOnline) signal.

connect(mgr, SIGNAL(onlineStateChanged(bool)), this, SLOT(onOnlineStateChanged(bool)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM