Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sorting of QNetworkInterface::allInterfaces() is different from 1st and 2nd call
Forum Updated to NodeBB v4.3 + New Features

Sorting of QNetworkInterface::allInterfaces() is different from 1st and 2nd call

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 589 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.
  • M Offline
    M Offline
    MECoder
    wrote on last edited by
    #1

    Hi,

    i'm using QNetworkInterface::allInterfaces() to fill a QComboBox with the humanReadableName()
    of each interface that was found.

    This is the qDebug() output off the QList<QNetworkInterface> (FIRST CALL)

    void MyNetworkInterface::fillComboBoxWithInterfaceList(QComboBox*) 
     (QNetworkInterface(name = "ethernet_32774", hardware address = "00:E1:02:00:10:05", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32775", hardware address = "00:50:B6:0B:86:6B", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32769", hardware address = "38:AF:D7:A5:24:01", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "wireless_32768", hardware address = "A0:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "wireless_32770", hardware address = "A2:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32770", hardware address = "A0:AF:BD:A9:0B:77", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "loopback_0", hardware address = "", flags = IsUp IsRunning CanBroadcast IsLoopBack CanMulticast [...]
    )
    

    Now, i connect 2 interfaces with cables, means that the flags will change and not SECOND CALL output:

    void MyNetworkInterface::fillComboBoxWithInterfaceList(QComboBox*) 
     (QNetworkInterface(name = "ethernet_32769", hardware address = "38:AF:D7:A5:24:01", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "wireless_32768", hardware address = "A0:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "wireless_32770", hardware address = "A2:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32774", hardware address = "00:E1:02:00:10:05", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32775", hardware address = "00:50:B6:0B:86:6B", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "ethernet_32770", hardware address = "A0:AF:BD:A9:0B:77", flags = CanBroadcast CanMulticast [...]
    , QNetworkInterface(name = "loopback_0", hardware address = "", flags = IsUp IsRunning CanBroadcast IsLoopBack CanMulticast [...]
    )
    

    If you compare both outputs, you will see that the order has changed. When i fill the ComboBox again, the order
    is completely different now. I want to avoid that i sort it by myself each time anything changes.
    The QComboBox is updated automatically with all possible interfaces by my Watchdog Class for network interfaces.
    The icon for each QComboBox entry depends on the flags if the interface is up and running.

    Does someone know why QNetworkInterface is sorting different? The interfaces didn't change, only the flags
    for the interface "ethernet_32774" and "ethernet_32775"

    JonBJ 1 Reply Last reply
    0
    • M MECoder

      Hi,

      i'm using QNetworkInterface::allInterfaces() to fill a QComboBox with the humanReadableName()
      of each interface that was found.

      This is the qDebug() output off the QList<QNetworkInterface> (FIRST CALL)

      void MyNetworkInterface::fillComboBoxWithInterfaceList(QComboBox*) 
       (QNetworkInterface(name = "ethernet_32774", hardware address = "00:E1:02:00:10:05", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32775", hardware address = "00:50:B6:0B:86:6B", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32769", hardware address = "38:AF:D7:A5:24:01", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "wireless_32768", hardware address = "A0:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "wireless_32770", hardware address = "A2:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32770", hardware address = "A0:AF:BD:A9:0B:77", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "loopback_0", hardware address = "", flags = IsUp IsRunning CanBroadcast IsLoopBack CanMulticast [...]
      )
      

      Now, i connect 2 interfaces with cables, means that the flags will change and not SECOND CALL output:

      void MyNetworkInterface::fillComboBoxWithInterfaceList(QComboBox*) 
       (QNetworkInterface(name = "ethernet_32769", hardware address = "38:AF:D7:A5:24:01", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "wireless_32768", hardware address = "A0:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "wireless_32770", hardware address = "A2:AF:BD:A9:0B:73", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32774", hardware address = "00:E1:02:00:10:05", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32775", hardware address = "00:50:B6:0B:86:6B", flags = IsUp IsRunning CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "ethernet_32770", hardware address = "A0:AF:BD:A9:0B:77", flags = CanBroadcast CanMulticast [...]
      , QNetworkInterface(name = "loopback_0", hardware address = "", flags = IsUp IsRunning CanBroadcast IsLoopBack CanMulticast [...]
      )
      

      If you compare both outputs, you will see that the order has changed. When i fill the ComboBox again, the order
      is completely different now. I want to avoid that i sort it by myself each time anything changes.
      The QComboBox is updated automatically with all possible interfaces by my Watchdog Class for network interfaces.
      The icon for each QComboBox entry depends on the flags if the interface is up and running.

      Does someone know why QNetworkInterface is sorting different? The interfaces didn't change, only the flags
      for the interface "ethernet_32774" and "ethernet_32775"

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @MECoder said in Sorting of QNetworkInterface::allInterfaces() is different from 1st and 2nd call:

      Nothing in the docs for QNetworkInterface::allInterfaces() says anything about the order returned, so no reason to expect any kind of sorting (e.g. for all we know the code may report interfaces using asynchronous calls). So sort your combobox by whatever you wish to sort by for your consistency, e.g. perhaps name.

      1 Reply Last reply
      4

      • Login

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