PDA

View Full Version : use of QNetworkAccessManager::networkAccessible



sky
4th January 2011, 11:05
Has anybody successfully used QNetworkAccessManager::networkAccessible ?
if so can you please post how I can use it? When I try to use it, it just returns a -1.

Thank you,
sky.

squidge
4th January 2011, 13:35
Which means it can not determine the accessibility of the network on the platform that you are running your application on.

sky
4th January 2011, 18:23
Thanks squidge. I should have poseted more details. Here they are:

Windows 7 professional, Intel i5.
my code looks like this:



if (pNetwork->networkAccessible()!=QNetworkAccessManager::Access ible)
{
qCritical()<<"Network is not accessible." <<pNetwork->networkAccessible();
while ((pNetwork->networkAccessible()!=QNetworkAccessManager::Access ible)) {}
}

And my code is always getting stuck in the while loop. While I am able to access the internet on the same computer all the while. :( Please let me know if I am missing anything. Thank you.

Berryblue031
28th April 2011, 14:04
I know this is an old thread but I stumbled across it while looking for an answer to same the question and thought I would update the thread with an answer

QNetworkAccessManager::networkAccessible is not explicitly set when the QNetworkAccessManager is created. It is only set after the network session is initialized. The session is initialized automatically when you make a network request or you can initialize it before hand with QNetworkAccessManager::setConfiguration() or the QNetworkConfigurationManager::NetworkSessionRequir ed flag is set.

Adding the following snippet of code after the QNetworkAccessManager is created would do the trick



QNetworkAccessManager* mNetworkAccessManager = new QNetworkAccessManager();
QNetworkConfigurationManager manager;
mNetworkAccessManager->setConfiguration(manager.defaultConfiguration());


now any subsequent calls to


mNetworkAccessManager->networkAccessible();

will return properly (instead of constantly returning QNetworkAccessManager::UnknownAccessibility (-1) )

llev
13th August 2011, 20:29
I'm not sure this is quite right.
My app throws many successful network requests through single QNetworkAccessManager.
Just tested for sure.
networkAccessible() remains -1, no networkAccessibleChanged signal emitted.
I saw such behavior on older Qt's and now see the same on 4.8.0b1. OS: Windows 7.

I didn't try to set configuration explicitly as you pointed as alternative case.

PS. I saw networkAccessible working in some way on Symbian^3 devices.