本文整理汇总了C++中QNetworkInterface::name方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkInterface::name方法的具体用法?C++ QNetworkInterface::name怎么用?C++ QNetworkInterface::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkInterface
的用法示例。
在下文中一共展示了QNetworkInterface::name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
}
示例2: getNetworkAddressEntry
/**
* @brief wavrNetwork::getNetworkAddressEntry
* @param pAddressEntry Gets the address entries from network interface and fills in this variable.
* @return Returns true opon success.
* Gets the address entries from network interface whether IPV4 or IPV6 and fills the data in pAddressEntry.
*/
bool wavrNetwork::getNetworkAddressEntry(QNetworkAddressEntry* pAddressEntry) {
// get the first active network interface
QNetworkInterface networkInterface;
if(getNetworkInterface(&networkInterface)) {
wavrTrace::write("Querying IP address from network interface...");
// get a list of all associated ip addresses of the interface
QList<QNetworkAddressEntry> addressEntries = networkInterface.addressEntries();
// return the first address which is an ipv4 address
for(int index = 0; index < addressEntries.count(); index++) {
if(addressEntries[index].ip().protocol() == QAbstractSocket::IPv4Protocol) {
*pAddressEntry = addressEntries[index];
this->networkInterface = networkInterface;
this->interfaceName = networkInterface.name();
wavrTrace::write("IPv4 address found for network interface.");
return true;
}
}
// if ipv4 address is not present, check for ipv6 address
for(int index = 0; index < addressEntries.count(); index++) {
if(addressEntries[index].ip().protocol() == QAbstractSocket::IPv6Protocol) {
*pAddressEntry = addressEntries[index];
this->networkInterface = networkInterface;
this->interfaceName = networkInterface.name();
wavrTrace::write("IPv6 address found for network interface.");
return true;
}
}
wavrTrace::write("Warning: No IP address found for network interface.");
}
return false;
}
示例3: 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();
}
示例4: item_text
// Set up bind address combobox
foreach (const QNetworkInterface &netif, QNetworkInterface::allInterfaces())
{
const QString &hname = netif.name();
foreach (const QNetworkAddressEntry &netaddr, netif.addressEntries())
{
const QHostAddress &addr = netaddr.ip();
if (addr.protocol() == QAbstractSocket::IPv4Protocol)
{
QString item_text(addr.toString() + " (" + hname + ")");
settings_dialog.bind_address->addItem(item_text, addr.toString());
}
}
}
示例5: findNameInPcap
int PortControler::findNameInPcap(QNetworkInterface &network)
{
QString networkName = network.name();
int i = 0;
for ( currDev = allDevs; currDev != nullptr; currDev = currDev->next )
{
QString intName = currDev->name;
if ( intName.contains( networkName ) )
{
return i;
}
++i;
}
return -1;
}
示例6: 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();
}
}
//.........这里部分代码省略.........
示例7: 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;
//.........这里部分代码省略.........