本文整理汇总了C++中QNetworkAccessManager::networkAccessible方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAccessManager::networkAccessible方法的具体用法?C++ QNetworkAccessManager::networkAccessible怎么用?C++ QNetworkAccessManager::networkAccessible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkAccessManager
的用法示例。
在下文中一共展示了QNetworkAccessManager::networkAccessible方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: networkAccessible
void tst_QNetworkAccessManager::networkAccessible()
{
QNetworkAccessManager manager;
qRegisterMetaType<QNetworkAccessManager::NetworkAccessibility>("QNetworkAccessManager::NetworkAccessibility");
QSignalSpy spy(&manager,
SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::NotAccessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::UnknownAccessibility);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
QNetworkConfigurationManager configManager;
QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
if (defaultConfig.isValid()) {
manager.setConfiguration(defaultConfig);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::Accessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
QNetworkAccessManager::NotAccessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
}
}
示例2: isNetworkAvailOnAppLaunch
void ApplicationUI::isNetworkAvailOnAppLaunch() {
QNetworkAccessManager *manager = new QNetworkAccessManager();
qDebug()<<"Checking ent";
QNetworkRequest req;
QString url = "http://www.google.com/";
req.setUrl(url);
// manager->networkAccessible();
qDebug()<<"mannger net"<<manager->networkAccessible();
// if(manager->networkAccessible()==QNetworkAccessManager::NotAccessible||manager->networkAccessible()==QNetworkAccessManager::UnknownAccessibility)
// {
// emit nonetwork();
// }
// else
// {
req.setHeader(QNetworkRequest::ContentTypeHeader, "text/xml"); //"gzip"
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkAvailabilityResponse(QNetworkReply *)));
manager->get(req);
// }
}
示例3: networkAccessible
void tst_QNetworkAccessManager::networkAccessible()
{
#ifndef QT_NO_BEARERMANAGEMENT
QNetworkAccessManager manager;
qRegisterMetaType<QNetworkAccessManager::NetworkAccessibility>("QNetworkAccessManager::NetworkAccessibility");
QSignalSpy spy(&manager,
SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
// if there is no session, we cannot know in which state we are in
QNetworkAccessManager::NetworkAccessibility initialAccessibility =
manager.networkAccessible();
if (initialAccessibility == QNetworkAccessManager::UnknownAccessibility)
QSKIP("Unknown accessibility", SkipAll);
QCOMPARE(manager.networkAccessible(), initialAccessibility);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
int expectedCount = (initialAccessibility == QNetworkAccessManager::Accessible) ? 1 : 0;
QCOMPARE(spy.count(), expectedCount);
if (expectedCount > 0)
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::NotAccessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
QCOMPARE(spy.count(), expectedCount);
if (expectedCount > 0)
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
initialAccessibility);
QCOMPARE(manager.networkAccessible(), initialAccessibility);
QNetworkConfigurationManager configManager;
QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
if (defaultConfig.isValid()) {
manager.setConfiguration(defaultConfig);
QCOMPARE(spy.count(), 0);
if (defaultConfig.state().testFlag(QNetworkConfiguration::Active))
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
else
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
if (defaultConfig.state().testFlag(QNetworkConfiguration::Active)) {
QCOMPARE(spy.count(), 1);
QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
QNetworkAccessManager::NotAccessible);
} else {
QCOMPARE(spy.count(), 0);
}
}
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
#endif
}