Unsolved Sorting of QNetworkInterface::allInterfaces() is different from 1st and 2nd call
-
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" -
@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. perhapsname
.