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


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

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


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

示例1: hasInternetConnection

/*
 * Checks if we have internet access!
 */
bool UnixCommand::hasInternetConnection()
{
  QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
  bool result = false;

  for (int i = 0; i < ifaces.count(); i++){
    QNetworkInterface iface = ifaces.at(i);

    if ( iface.flags().testFlag(QNetworkInterface::IsUp)
         && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) ){
      for (int j=0; j<iface.addressEntries().count(); j++){
        /*
         We have an interface that is up, and has an ip address
         therefore the link is present.

         We will only enable this check on first positive,
         all later results are incorrect
        */
        if (result == false)
          result = true;
      }
    }
  }

  //It seems to be alright, but let's make a ping to see the result
  /*if (result == true)
  {
    result = UnixCommand::doInternetPingTest();
  }*/

  return result;
}
开发者ID:aarnt,项目名称:octoxbps,代码行数:35,代码来源:unixcommand.cpp

示例2: settings

bool
Utilities::isOnline(QNetworkAccessManager *manager)
{
    bool ret = false;
    QSettings settings("Entomologist");
    if (settings.value("work-offline", false).toBool())
        return(false);

#if QT_VERSION >= 0x040700
    if (manager->networkAccessible() != QNetworkAccessManager::NotAccessible)
        ret = true;
    else
        ret = false;
#else
    QNetworkInterface iface;
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();

    for (int i = 0; i < ifaces.count(); ++i)
    {
        iface = ifaces.at(i);
        if (iface.flags().testFlag(QNetworkInterface::IsUp)
            && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
        {
            if (iface.addressEntries().count() >= 1)
            {
                ret = true;
                break;
            }
        }
    }
#endif

    return(ret);
}
开发者ID:Entomologist,项目名称:entomologist,代码行数:34,代码来源:Utilities.cpp

示例3: isConnectedToNetwork2

bool isConnectedToNetwork2()
{
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    bool result = false;

    for (int i = 0; i < ifaces.count(); i++)
    {
        QNetworkInterface iface = ifaces.at(i);
        if ( iface.flags().testFlag(QNetworkInterface::IsUp)
             && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
        {


            // this loop is important
            for (int j=0; j<iface.addressEntries().count(); j++)
            {

                // we have an interface that is up, and has an ip address
                // therefore the link is present

                // we will only enable this check on first positive,
                // all later results are incorrect

                if (result == false)
                    result = true;
            }
        }

    }

    return result;
}
开发者ID:albo1962,项目名称:adbFire,代码行数:32,代码来源:preferencesdialog.cpp

示例4: checkNetwork

void ImageProcessing::checkNetwork()
{
	bool running = false;
	QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();

	qWarning() << __FUNCTION__ << ": Running the network check";
	if (pNextImage->isActive()) {
		qWarning() << __FUNCTION__ << ": Turning off image display timer";
		pNextImage->stop();
	}
	for (int i = 0; i < interfaces.size(); i++) {
		QNetworkInterface ni = interfaces[i];
		if (ni.name() != "wlan0")
			continue;

		qWarning() << __FUNCTION__ << ": Checking interface" << ni.name() << " with flags" << ni.flags();

		if (ni.flags().testFlag(QNetworkInterface::IsUp) && ni.flags().testFlag(QNetworkInterface::IsRunning)) {
			running = true;
			getContentList();
		}
	}
	if (!running) {
		qWarning() << __FUNCTION__ << ": Network check didn't find an available interface";
		showLocalImage();
	}
}
开发者ID:buelowp,项目名称:pictureframe,代码行数:27,代码来源:ImageProcessing.cpp

示例5: QObject

OceanSocket::OceanSocket(QObject *parent) :
    QObject(parent)
{
    // setup the heartbeat timer
    heartbeat = new QTimer(this);
    connect(heartbeat, SIGNAL(timeout()), this, SLOT(heartbeatTimer()));

    // setup our ocean sockets
    groupAddress = QHostAddress(MULTICAST_ADDRESS);

    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    for (int i = 0; i < ifaces.count(); i++) {
        QNetworkInterface iface = ifaces.at(i);
        if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) && iface.flags().testFlag(QNetworkInterface::CanMulticast)) {
            for (int j = 0; j < iface.addressEntries().count(); j++) {
                if (iface.addressEntries().at(j).ip().protocol() != QAbstractSocket::IPv4Protocol) continue;
                qDebug() << "Ocean bind to iface: " << iface.name() << endl << "IP: " << iface.addressEntries().at(j).ip().toString() << endl;
                QUdpSocket* socket = new QUdpSocket(this);
                socket->bind(QHostAddress::AnyIPv4, 8047, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
                socket->joinMulticastGroup(groupAddress, iface);
                connect(socket, SIGNAL(readyRead()), this, SLOT(processIncomingWaves()));
                boundAddresses.append(iface.addressEntries().at(j).ip());
                multicastSockets.append(socket);
            }
        }
    }

    sendSocket = new QUdpSocket(this);
    sendSocket->bind();
}
开发者ID:JonnyFunFun,项目名称:FilePirate,代码行数:30,代码来源:oceansocket.cpp

示例6: gconf_value_changed

void SpeedWrapper::gconf_value_changed()
{
    bool ok;
    //check netspeed enabled
    if(!m_gconf_enabled->value().isValid())
        m_gconf_enabled->set(true);
    //check netspeed interface
    if(!m_gconf_speed_interface->value().isValid())
        m_gconf_speed_interface->set("wlan0");
    //check netspeed update time
    if(!m_gconf_update_time->value().isValid())
        m_gconf_update_time->set(1000);
    //check when online
    if(!m_gconf_when_online->value().isValid())
        m_gconf_when_online->set(false);


    m_is_enabled = m_gconf_enabled->value().toBool();
    m_speed_interface = m_gconf_speed_interface->value().toString();
    m_when_online = m_gconf_when_online->value().toBool();

    if(m_speed_interface.isEmpty() || m_speed_interface.isNull())
        m_speed_interface = "wlan0";
    m_update_time = m_gconf_update_time->value().toInt(&ok);
    if(!ok)
        m_update_time = 1000;

    QNetworkInterface interface = QNetworkInterface::interfaceFromName(m_speed_interface);
    m_network_interface_valid = interface.isValid();
    bool online = (interface.flags().testFlag(QNetworkInterface::IsUp) &&
                  interface.flags().testFlag(QNetworkInterface::IsRunning));
    if(online != m_isOnline)
    {
        emit onlineChanged(online);
        updateData();
    }
    m_isOnline = online;

    if(m_is_enabled)
    {
        if(m_when_online)
        {
            if(m_isOnline)
            {
                m_timer->stop();
                m_timer->start(m_update_time);
            }else{
                m_timer->stop();
            }
        }else{
            m_timer->stop();
            m_timer->start(m_update_time);
        }
    }else{
        m_timer->stop();
    }
}
开发者ID:CODeRUS,项目名称:unrestricted-system-ui,代码行数:57,代码来源:speedwrapper.cpp

示例7: onlineStateChange

void MainWindow::onlineStateChange()
{
    static bool netUp = false;
    bool bState = false;
    QNetworkInterface netInterface = QNetworkInterface::interfaceFromName(NET_NAME);
    //qDebug()<<netInterface;
    if (netInterface.isValid())
    {
        if (netInterface.flags().testFlag(QNetworkInterface::IsUp) && 
            netInterface.flags().testFlag(QNetworkInterface::IsRunning))
        {
            if (!netUp) 
            {
                repaint();
                netUp = true;
            }
            QHostInfo host = QHostInfo::fromName(WEB_SITE);
            if (!host.addresses().isEmpty()) 
            {
                repaint();
                Global::s_netState = true;
                bState = true;
                m_shangChun->UploadData();
            }
            else
            {
                repaint();
                Global::s_netState = false;
                bState = false;
            }
        }
        else
        {
            repaint();
            Global::s_netState = false;
            bState = false;
            netUp = false;
        }
    }

    if(bState)
    {
        QImage NetImage(":/images/NetConn24.ico");
        this->network->setPixmap(QPixmap::fromImage(NetImage));
    }
    else
    {
        QImage NetImage(":/images/NetDisConn24.ico");
        this->network->setPixmap(QPixmap::fromImage(NetImage));
    }

    SetUnUpCount();
}
开发者ID:lijingshy,项目名称:usbW,代码行数:53,代码来源:mainwindow.cpp

示例8: accessPointChanged

    // Go through all interfaces and add all IPs for interfaces that can
    // broadcast and are not local.
    foreach (QNetworkInterface networkInterface,
             QNetworkInterface::allInterfaces())
    {
        if (!networkInterface.addressEntries().isEmpty()
                && networkInterface.isValid())
        {
            QNetworkInterface::InterfaceFlags interfaceFlags =
                    networkInterface.flags();

            if (interfaceFlags & QNetworkInterface::IsUp
                    && interfaceFlags & QNetworkInterface::IsRunning
                    && interfaceFlags & QNetworkInterface::CanBroadcast
                    && !(interfaceFlags & QNetworkInterface::IsLoopBack))
            {
                qDebug() << "ConnectionManager::handleNetworkSessionOpened():"
                         << "The connection is valid!";

                if (mNetworkSession) {
                    mAccessPoint = mNetworkSession->configuration().name();
                    emit accessPointChanged(mAccessPoint);
                }

                mMyIp.setAddress(networkInterface.addressEntries().at(0).ip().toString());
                emit myIpChanged(mMyIp.toString());

                setState(Connected);
                return;
            }
        }
    }
开发者ID:Alex237,项目名称:tic-tac-toe-qt,代码行数:32,代码来源:connectionmanager.cpp

示例9: foreach

 //Source : http://stackoverflow.com/a/7616111
 foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
     {
         // Return only the first non-loopback MAC Address
         if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)){
             macAddress = netInterface.hardwareAddress();
             break;
         }
     }
开发者ID:jkehelwala,项目名称:nifdaaclient,代码行数:9,代码来源:ocproperties.cpp

示例10: sendMessage

bool OceanSocket::sendMessage(const char message_type, QString data)
{
    QByteArray pulse = QString(message_type+data).toUtf8();
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    for (int i = 0; i < ifaces.count(); i++) {
        QNetworkInterface iface = ifaces.at(i);
        if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) && iface.flags().testFlag(QNetworkInterface::CanMulticast)) {
            bool isIp4 = false;
            for (int j = 0; j < iface.addressEntries().count(); j++) {
                if (iface.addressEntries().at(j).ip().scopeId() == "")
                    isIp4 = true;
            }
            if (isIp4) {
                sendSocket->setMulticastInterface(iface);
                sendSocket->writeDatagram(pulse.data(), pulse.size(), groupAddress, 8047);
            }
        }
    }

    return true;
}
开发者ID:JonnyFunFun,项目名称:FilePirate,代码行数:21,代码来源:oceansocket.cpp

示例11: getplayerMACAddress

void squeezeLiteGui::getplayerMACAddress(void)
{
    DEBUGF("");
    MacAddress = QByteArray( "00:00:00:00:00:04" );

    QList<QNetworkInterface> netList = QNetworkInterface::allInterfaces();
    QListIterator<QNetworkInterface> i( netList );

    QNetworkInterface t;

    while( i.hasNext() ) {  // note: this grabs the first functional, non-loopback address there is.  It may not the be interface on which you really connect to the slimserver
        t = i.next();
        if( !t.flags().testFlag( QNetworkInterface::IsLoopBack ) &&
                t.flags().testFlag( QNetworkInterface::IsUp ) &&
                t.flags().testFlag( QNetworkInterface::IsRunning ) ) {
            MacAddress = t.hardwareAddress().toLatin1().toLower();
            if(!MacAddress.contains("%3A")) // not escape encoded
                encodedMacAddress = QString(MacAddress).toLatin1().toPercentEncoding();
            return;
        }
    }
}
开发者ID:ggalt,项目名称:squeezelitegui,代码行数:22,代码来源:squeezelitegui.cpp

示例12: updateConfigurations

void QAndroidBearerEngine::updateConfigurations()
{
#ifndef QT_NO_NETWORKINTERFACE
    if (m_connectivityManager == 0)
        return;

    {
        QMutexLocker locker(&mutex);
        QStringList oldKeys = accessPointConfigurations.keys();

        QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
        if (interfaces.isEmpty())
            interfaces = QNetworkInterface::allInterfaces();

        // Create a configuration for each of the main types (WiFi, Mobile, Bluetooth, WiMax, Ethernet)
        foreach (const AndroidNetworkInfo &netInfo, m_connectivityManager->getAllNetworkInfo()) {

            if (!netInfo.isValid())
                continue;

            const QString name = networkConfType(netInfo);
            if (name.isEmpty())
                continue;

            QNetworkConfiguration::BearerType bearerType = getBearerType(netInfo);

            QString interfaceName;
            QNetworkConfiguration::StateFlag state = QNetworkConfiguration::Defined;
            if (netInfo.isAvailable()) {
                if (netInfo.isConnected()) {
                    // Attempt to map an interface to this configuration
                    while (!interfaces.isEmpty()) {
                        QNetworkInterface interface = interfaces.takeFirst();
                        // ignore loopback interface
                        if (!interface.isValid())
                            continue;

                        if (interface.flags() & QNetworkInterface::IsLoopBack)
                            continue;
                        // There is no way to get the interface from the NetworkInfo, so
                        // look for an active interface...
                        if (interface.flags() & QNetworkInterface::IsRunning
                                && !interface.addressEntries().isEmpty()) {
                            state = QNetworkConfiguration::Active;
                            interfaceName = interface.name();
                            break;
                        }
                    }
                }
            }

            const QString key = QString(QLatin1String("android:%1:%2")).arg(name).arg(interfaceName);
            const QString id = QString::number(qHash(key));
            m_configurationInterface[id] = interfaceName;

            oldKeys.removeAll(id);
            if (accessPointConfigurations.contains(id)) {
                QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
                bool changed = false;
                {
                    const QMutexLocker confLocker(&ptr->mutex);

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

                    // Don't reset the bearer type to 'Unknown'
                    if (ptr->bearerType != QNetworkConfiguration::BearerUnknown
                            && ptr->bearerType != bearerType) {
                        ptr->bearerType = bearerType;
                        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;
                    }
                } // Unlock configuration

                if (changed) {
                    locker.unlock();
                    Q_EMIT configurationChanged(ptr);
                    locker.relock();
                }
            } else {
                QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
                ptr->name = name;
                ptr->isValid = true;
                ptr->id = id;
//.........这里部分代码省略.........
开发者ID:James-intern,项目名称:Qt,代码行数:101,代码来源:qandroidbearerengine.cpp

示例13:

	foreach( QNetworkInterface netIf, QNetworkInterface::allInterfaces( ) ) {
		if( !( netIf.flags( ) & QNetworkInterface::IsLoopBack ) ) {
			return netIf.hardwareAddress( );
		}
	}
开发者ID:Eurospider,项目名称:TimeSpider,代码行数:5,代码来源:TimeSpiderSettingsDialog.cpp

示例14: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

	//qInstallMsgHandler(customMessageHandler);	

#ifdef ARM
    //font
    QFont font;
    font.setPointSize(16);
    a.setFont(font);
#endif

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");  

    QTextCodec::setCodecForLocale(codec);  
    QTextCodec::setCodecForCStrings(codec);  
    QTextCodec::setCodecForTr(codec);

    //create dir for update
    QDir appDir;
    appDir.mkpath(TMP_PATH);
    appDir.mkpath(APK_PATH);
    appDir.mkpath(LOG_PATH);
    appDir.mkpath(ENCYPT_LOG_PATH);

    //test network
    int time = 2;
    while(time)
    {
        QNetworkInterface netInterface = QNetworkInterface::interfaceFromName(NET_NAME);
        if (netInterface.isValid())
        {
            if (netInterface.flags().testFlag(QNetworkInterface::IsUp))
            {
                QHostInfo host = QHostInfo::fromName(WEB_SITE);
                if (!host.addresses().isEmpty()) 
                {
                    Global::s_netState = true;
                    break;
                }
            }
        }
        sleep(5);
        --time;
    }

    //msgBox.hide();

    if (!Global::s_netState)
    {
        QMessageBox::information(NULL, APP_NAME, "没有发现网络连接,无法更新软件数据,系统将离线运行!");
    }

    MainWindow w;
    w.setWindowTitle("Welcome");
    w.show();

    if (Global::s_netState)
    {
        Gengxin gengXin(true);
        gengXin.show();
        gengXin.StartUpSoft();
#if 0
        if (Global::s_needRestart)
        {
            QString exePath = qApp->applicationFilePath();
            QString cmd = "unzip ";
            cmd += UPDATE_FILE_NAME;
            QFile::remove(exePath);
            QProcess::execute(cmd);
#ifdef ARM
            Global::reboot();
#else
            QProcess::startDetached(exePath, QStringList());
#endif
            return 0;
        }
#endif
        gengXin.hide();
        if (gengXin.getUpdateDevState())
            w.OnGengxin(false);
        else
            w.startUsbScan();
    }

    return a.exec();
}
开发者ID:lijingshy,项目名称:usbW,代码行数:88,代码来源:main.cpp

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