c++ - How to detect internet connection state with Qt 5.4 on OS X Yosemite 10.10.3? -
i'm trying check internet connection state qt 5.4 on os x yosemite 10.10.3, every time run code result connected, although i'm not connected anything.
bool networkaccessmanager::currentconnectivitystatus() { qnetworkaccessmanager *namanager = new qnetworkaccessmanager(this); switch (namanager->networkaccessible()) { case qnetworkaccessmanager::unknownaccessibility: kdebug() << q_func_info << "qnetworkaccessmanager::unknownaccessibility"; break; case qnetworkaccessmanager::notaccessible: kdebug() << q_func_info << "qnetworkaccessmanager::notaccessible"; break; case qnetworkaccessmanager::accessible: kdebug() << q_func_info << "qnetworkaccessmanager::accessible"; break; default: break; } qnetworkconfigurationmanager manager; kdebug()<< q_func_info << " network connection " << manager.isonline(); qnetworkconfiguration cfg = manager.defaultconfiguration(); qnetworksession *session = new qnetworksession(cfg); session->open(); session->waitforopened(); if(session->isopen()) { switch (session->state()) { case qnetworksession::connected: kdebug() << q_func_info << "qnetworksession::connected"; break; case qnetworksession::disconnected: kdebug() << q_func_info << "qnetworksession::disconnect"; break; default: break; } } }
and here result above when disconnect everything
debug 2015-04-25t16:00:59.560 bool networkaccessmanager::currentconnectivitystatus() qnetworkaccessmanager::accessible debug 2015-04-25t16:00:59.560 bool networkaccessmanager::currentconnectivitystatus() network connection ok true debug 2015-04-25t16:00:59.560 bool networkaccessmanager::currentconnectivitystatus() qnetworksession::connected
pinging c/c++ program here how ping external server, implement , if pings return true , if not, false.
Comments
Post a Comment