本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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();
}
}
//.........这里部分代码省略.........