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


C++ QNetworkInterface::humanReadableName方法代码示例

本文整理汇总了C++中QNetworkInterface::humanReadableName方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkInterface::humanReadableName方法的具体用法?C++ QNetworkInterface::humanReadableName怎么用?C++ QNetworkInterface::humanReadableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QNetworkInterface的用法示例。


在下文中一共展示了QNetworkInterface::humanReadableName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: scan

void PJobRunnerNetworkScanner::scan(const QNetworkInterface& interface){
    foreach(const QNetworkAddressEntry& address_entry, interface.addressEntries()){
        if(m_want_stop) break;
        quint32 netmask = address_entry.netmask().toIPv4Address();
        quint32 local_ip = address_entry.ip().toIPv4Address();
        quint32 address_to_try = (local_ip & netmask) + 1;
        //quint32 inv_netmask = ~netmask;

        if(interface.humanReadableName() == "lo"){
            std::cout << "Skipping interface \"lo\"." << std::endl;
            continue;
        }

        if(!interface.isValid()){
            std::cout << "Skipping interface \"" << interface.humanReadableName().toStdString() << "\"." << std::endl;
            continue;
        }

        if(address_entry.ip().protocol() != QAbstractSocket::IPv4Protocol){
            std::cout << "Skipping non-IPv4 interface." << std::endl;
            continue;
        }

        if(address_entry.ip() == QHostAddress::LocalHost){
            std::cout << "Skipping loopback interface." << std::endl;
            continue;
        }

        if(address_entry.ip().isNull()){
            continue;
        }

        std::cout << "Probing interface " << interface.humanReadableName().toStdString() << std::endl;
        std::cout << "Local address is " << interface.hardwareAddress().toStdString() << std::endl;
        std::cout << "Netmask: " << address_entry.netmask().toString().toStdString() << std::endl;
        std::cout << "Searching local network..." << std::endl;
        while((address_to_try & netmask) == (local_ip & netmask)){
            if(m_want_stop) break;
            std::cout << "\r" << QHostAddress(address_to_try).toString().toStdString();
            std::cout.flush();
            emit probing_host(QHostAddress(address_to_try));
            PJobRunnerSessionWrapper* session = new PJobRunnerSessionWrapper(QHostAddress(address_to_try), 50);
            if(session->is_valid()) found(session);
            else delete session;
            address_to_try++;
        }
    }
    emit finished_scanning();
    m_want_stop = false;
}
开发者ID:lucksus,项目名称:PJob,代码行数:50,代码来源:pjobrunnernetworkscanner.cpp

示例2: openConnection

bool Network::openConnection(QString &netInterface)
{
    // Internet Access Point
    QNetworkConfigurationManager manager;

    const bool canStartIAP = (manager.capabilities()
        & QNetworkConfigurationManager::CanStartAndStopInterfaces);

    // If there is a default access point, use it
    QNetworkConfiguration cfg = manager.defaultConfiguration();

    if (!cfg.isValid() || !canStartIAP) {
        return false;
    }

    // Open session
    m_session = new QNetworkSession(cfg);
    m_session->open();
    // Waits for session to be open and continues after that
    m_session->waitForOpened();

    // Show interface name to the user
    QNetworkInterface iff = m_session->interface();
    netInterface = iff.humanReadableName();
    return true;
}
开发者ID:LameLefty,项目名称:spaghetti-code,代码行数:26,代码来源:network.cpp

示例3: populateAdaptors

void ConfigureDlg::populateAdaptors()
{
	QNetworkInterface		cInterface;
	int index;

	m_adaptor->insertItem(0, "<any>");
	index = 1;
	QList<QNetworkInterface> ani = QNetworkInterface::allInterfaces();
	foreach (cInterface, ani)
		m_adaptor->insertItem(index++, cInterface.humanReadableName());
}
开发者ID:robotage,项目名称:SyntroApps,代码行数:11,代码来源:ConfigureDlg.cpp

示例4: doRequestUpdate

void QGenericEngine::doRequestUpdate()
{
#ifndef QT_NO_NETWORKINTERFACE
    QMutexLocker locker(&mutex);

    // Immediately after connecting with a wireless access point
    // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
    // second time results in a non-empty list. If we loose interfaces we will end up removing
    // network configurations which will break current sessions.
    QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
    if (interfaces.isEmpty())
        interfaces = QNetworkInterface::allInterfaces();

    QStringList previous = accessPointConfigurations.keys();

    // create configuration for each interface
    while (!interfaces.isEmpty()) {
        QNetworkInterface interface = interfaces.takeFirst();

        if (!interface.isValid())
            continue;

        // ignore loopback interface
        if (interface.flags() & QNetworkInterface::IsLoopBack)
            continue;

        // ignore WLAN interface handled in separate engine
        if (qGetInterfaceType(interface.name()) == QNetworkConfiguration::BearerWLAN)
            continue;

        uint identifier;
        if (interface.index())
            identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
        else
            identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());

        const QString id = QString::number(identifier);

        previous.removeAll(id);

        QString name = interface.humanReadableName();
        if (name.isEmpty())
            name = interface.name();

        QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;
        if((interface.flags() & QNetworkInterface::IsUp) && !interface.addressEntries().isEmpty())
            state |= QNetworkConfiguration::Active;

        if (accessPointConfigurations.contains(id)) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

            bool changed = false;

            ptr->mutex.lock();

            if (!ptr->isValid) {
                ptr->isValid = true;
                changed = true;
            }

            if (ptr->name != name) {
                ptr->name = name;
                changed = true;
            }

            if (ptr->id != id) {
                ptr->id = id;
                changed = true;
            }

            if (ptr->state != state) {
                ptr->state = state;
                changed = true;
            }

            ptr->mutex.unlock();

            if (changed) {
                locker.unlock();
                emit configurationChanged(ptr);
                locker.relock();
            }
        } else {
            QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

            ptr->name = name;
            ptr->isValid = true;
            ptr->id = id;
            ptr->state = state;
            ptr->type = QNetworkConfiguration::InternetAccessPoint;
            ptr->bearerType = qGetInterfaceType(interface.name());

            accessPointConfigurations.insert(id, ptr);
            configurationInterface.insert(id, interface.name());

            locker.unlock();
            emit configurationAdded(ptr);
            locker.relock();
        }
    }
//.........这里部分代码省略.........
开发者ID:husninazer,项目名称:qt,代码行数:101,代码来源:qgenericengine.cpp


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