Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer
Accepted Solution

HowTo Test for active Internet connection.

Hi,

 

I'm testing for an active connection to the internet when my app first lauches,  this seems to work correctly on most machines, but it has been reported that it has hung on some other machines..  could someone please let me know if there is something wrong with the code I'm using below or if there is a better approach which I should be using?

 

Thank you in advance,

 

This is my code..

MyClass::MyClass

(QObject* parent)

:

QObject(parent)

{

QStringList serviceProviders = QGeoServiceProvider::availableServiceProviders();
    if ( serviceProviders.size() ) {
     m_provider = new QtMobilitySubset::QGeoServiceProvider( serviceProviders.at(0) );
     m_searchManager = m_provider->searchManager();
    }

    IsNetworkAlive = false;
    statusEventHandler = new StatusEventHandler();
        connect(statusEventHandler, SIGNAL(networkStatusUpdated(bool, QString)),
                this, SLOT(networkStatusUpdateHandler(bool, QString)));

 }

 

 

void MyClass::networkStatusUpdateHandler(bool status, QString type) {
    if (status) {
        //networkStatusLabel->setText("Network Status: true");
     IsNetworkAlive = true;
    } else {
        //networkStatusLabel->setText("Network Status: false");
     IsNetworkAlive = false;

    }
    //networkStatusType->setText("Network Type: " + type);
}



GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: HowTo Test for active Internet connection.

https://developer.blackberry.com/cascades/reference/qnetworkaccessmanager.html#networkAccessible-pro...

for an event based system i got the best results by using bps directly.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Re: HowTo Test for active Internet connection.

[ Edited ]

Hi,

 

Doesn't seem to work for me:, I've tried both:

 

THIS

******

 

 

QNetworkAccessManager

* mNetworkAccessManager = newQNetworkAccessManager();

if ( mNetworkAccessManager->networkAccessible() ==QNetworkAccessManager::Accessible)

{

IsNetworkAlive = true;

qDebug("Network Connection");

}

else

    qDebug("No Network Connection");

 

 

AND THIS

************

According to the post at: http://www.qtcentre.org/threads/37514-use-of-QNetworkAccessManager-networkAccessible

 

still no cigar,

 

QNetworkAccessManager

* mNetworkAccessManager = newQNetworkAccessManager();

QNetworkConfigurationManager manager;

mNetworkAccessManager->setConfiguration(manager.defaultConfiguration());

 

if ( mNetworkAccessManager->networkAccessible() ==QNetworkAccessManager::Accessible)

{

IsNetworkAlive = true;

qDebug("Network Connection");

}

else

    qDebug("No Network Connection");



GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: HowTo Test for active Internet connection.

Here is the code i used for bps:

//init
bps_initialize();
subscribe(netstatus_get_domain());
netstatus_request_events(0);

 

void xx::event(bps_event_t *event) {
	// Handle event
	if (bps_event_get_domain(event) == netstatus_get_domain()) {
		bool netAvail = false;
		netstatus_get_availability(&netAvail);
		//do stuff		
	}
}

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Re: HowTo Test for active Internet connection.

Great thanks,



GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!