Obtaining MAC address on windows in Qt

前端 未结 2 514
一生所求
一生所求 2021-01-17 12:16

I am attempting to obtain mac address on windows xp using this code:

QString getMacAddress()
{
QString macaddress=\"??:??:??:??:??:??\";
#ifdef Q_WS_WIN
PIP_         


        
2条回答
  •  野的像风
    2021-01-17 13:02

    With Qt and the QtNetwork module, you can get one of the MAC addresses like that:

    QString getMacAddress()
    {
        foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
        {
            // Return only the first non-loopback MAC Address
            if (!(netInterface.flags() & QNetworkInterface::IsLoopBack))
                return netInterface.hardwareAddress();
        }
        return QString();
    }
    

提交回复
热议问题