i cannot understand below if condition. if anyone know about it then please help me to understand it.
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
{
if(!(netInterface.flags() & netInterface.IsLoopBack))
{
qDebug()<<netInterface.humanReadableName();
qDebug()<<netInterface.hardwareAddress();
}
}
First lets start with the simple part: The logical negation operator
!.For any logical operation, the
!reverses the status of that operation. So!trueisfalse, and!falseistrue.netInterface.IsLoopBackis the value of a single bit.netInterface.flags()returns a set of bits.netInterface.flags() & netInterface.IsLoopBackchecks if the specific bitnetInterface.IsLoopBackis in the set returned bynetInterface.flags().Now putting it together, the result of
netInterface.flags() & netInterface.IsLoopBackis an integer value. If the bit is in the set then it's non-zero.In C++ all non-zero integer values is considered "true".
Applying the
!operator on this value reverses the condition.So the condition
!(netInterface.flags() & netInterface.IsLoopBack)will betrueis the bit is not in the set.Lastly a bit of context: The loop iterates over all network interfaces on the local system.
If an interface is not a loopback interface (the address
127.0.0.1is a loopback address) then the name and address of the interface is printed.Addendum: All of this could have been figured out relatively easy by reading some decent C++ books for the operators. And reading the documentation for
QNetworkInterface::flags()andenum QNetworkInterface::InterfaceFlag.