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.
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.
Which means it can not determine the accessibility of the network on the platform that you are running your application on.
Thanks squidge. I should have poseted more details. Here they are:
Windows 7 professional, Intel i5.
my code looks like this:
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.Qt Code:
if (pNetwork->networkAccessible()!=QNetworkAccessManager::Accessible) { qCritical()<<"Network is not accessible." <<pNetwork->networkAccessible(); while ((pNetwork->networkAccessible()!=QNetworkAccessManager::Accessible)) {} }To copy to clipboard, switch view to plain text modePlease let me know if I am missing anything. Thank you.
Last edited by sky; 4th January 2011 at 18:25. Reason: formating
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
Qt Code:
QNetworkAccessManager* mNetworkAccessManager = new QNetworkAccessManager(); QNetworkConfigurationManager manager; mNetworkAccessManager->setConfiguration(manager.defaultConfiguration());To copy to clipboard, switch view to plain text mode
now any subsequent calls to
Qt Code:
mNetworkAccessManager->networkAccessible();To copy to clipboard, switch view to plain text mode
will return properly (instead of constantly returning QNetworkAccessManager::UnknownAccessibility (-1) )
sky (14th June 2011)
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.
Bookmarks