Unsolved QNetworkConfiguration with wrong bearer type
-
I've a problem when Qt returns a wrong QNetworkConfiguration for a specific bearer type.
Trying to resolve the QHostAddress e.g. for ethernet interface returns (sometimes!) the address of WiFi adapter.Here is a code example:
// ---------------------------------------------------------------------------- // getHostAddress (static) // ---------------------------------------------------------------------------- QHostAddress NetworkTools::getHostAddress(const QNetworkConfiguration::BearerType &in_bearer_type) { if (in_bearer_type == QNetworkConfiguration::BearerUnknown) return QHostAddress(); QNetworkConfigurationManager nwc_manager; QList<QNetworkConfiguration> nwc_list = nwc_manager.allConfigurations(QNetworkConfiguration::Active); if (nwc_list.isEmpty()) return QHostAddress(); bool found = false; QNetworkConfiguration nwc; foreach (nwc, nwc_list) { if (nwc.bearerType() == in_bearer_type) { found = true; break; } } if (found == false) return QHostAddress(); qDebug() << "NetworkTools::getHostAddress - found bearer type:" << nwc.bearerTypeName(); QNetworkSession nws(nwc); if (nws.state() == QNetworkSession::Invalid || nws.state() == QNetworkSession::NotAvailable) return QHostAddress(); qDebug() << "NetworkTools::getHostAddress - session state:" << nws.state(); QNetworkInterface nwi = nws.interface(); if (nwi.isValid() == false) return QHostAddress(); if (nwi.addressEntries().isEmpty()) return QHostAddress(); foreach(QNetworkAddressEntry temp, nwi.addressEntries()) qDebug() << "NetworkTools::getHostAddress - session addr entry:" << temp.ip().toString(); QNetworkAddressEntry nwae = nwi.addressEntries().first(); QHostAddress host_address = nwae.ip(); return host_address; }
BTW: I'm using Qt 5.5.1 / MSVC2013-32bit compiler under Windows 7.
-
just a push ...