QNetworkInterface::addressEntries() returns empty list
Unsolved
Mobile and Embedded
-
Hello,
I am relying on QNetworkInterface::addressEntries() to get the IP address of an interface, in this case eth0. Every 10 seconds the following code is executed:
QList<QNetworkInterface> interfaceList= QNetworkInterface::allInterfaces(); QList<QNetworkAddressEntry> entries; if(!interfaceList.empty()) { QNetworkInterface interface; foreach (interface, interfaceList) { if (interface.name().startsWith("e") && interface.addressEntries().size() !=0) { entries = interface.addressEntries(); // Do something with the interface } } }
To check if the connection is actually still there I used the ip addr command and have seen that the IPs are still ok. However as addressEntries() are empty my code could not proceed.
Currently I am using Qt 5.9.6, IP address set to DHCP.
Is this a known issue? Any ideas how to solve this problem?
Regards,
Dule -
@DrEmbo said in QNetworkInterface::addressEntries() returns empty list:
allInterfaces
this works for me with Qt 5.15.2 on Linux.
QList< QNetworkInterface > network_interfaces = QNetworkInterface::allInterfaces(); for( auto interface : network_interfaces ) { if ( interface.flags().testFlag( QNetworkInterface::IsRunning ) ) { auto address_entries = interface.addressEntries(); for ( auto address_entry : address_entries ) { .................. } } }