Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QNetworkInterface::addressEntries() returns empty list
Forum Updated to NodeBB v4.3 + New Features

QNetworkInterface::addressEntries() returns empty list

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
embeddednetworking
2 Posts 2 Posters 465 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DrEmbo
    wrote on 3 Jan 2023, 09:38 last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 3 Jan 2023, 20:08 last edited by
      #2

      @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 ) {
                            ..................
                  }
              }
         }
      
      1 Reply Last reply
      0

      1/2

      3 Jan 2023, 09:38

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved