当前位置: 首页>>代码示例>>C++>>正文


C++ QNetworkAccessManager::networkAccessible方法代码示例

本文整理汇总了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);
    }
}
开发者ID:KDE,项目名称:android-qt,代码行数:43,代码来源:tst_qnetworkaccessmanager.cpp

示例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);
//	}
}
开发者ID:saibandla,项目名称:Cute-Weather,代码行数:22,代码来源:applicationui.cpp

示例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
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:61,代码来源:tst_qnetworkaccessmanager.cpp


注:本文中的QNetworkAccessManager::networkAccessible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。