Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get/generate unique Hardware ID for MAC OS



  • Hello Experts,

    I need to get/generate a unique hardware ID for MAC OS.
    For windows OS I am using below function for unique ID, but it is not working for MAC OS.

    @
    //generate Mac address
    QString Registration::generateMac()
    {
    foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
    {
    // Return only the first non-loopback MAC Address
    if (!(interface.flags() & QNetworkInterface::IsLoopBack))
    return interface.hardwareAddress();
    }
    return QString();
    }
    @

    Please suggest.

    Thanks in advance.
    Zain



  • What version of Qt and Mac OS are you using?



  • QT version:4.8.1
    MAC OS:Mac Lion 10.7.5



  • When I was searching for a solution to this problem, I came across this thread: http://stackoverflow.com/questions/933460/unique-hardware-id-in-mac-os-x
    The persons says he ended up using this:
    @
    QProcess proc;

    QStringList args;
    args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { print $3; }'";
    proc.start( "/bin/bash", args );
    proc.waitForFinished();

    QString uID = proc.readAll();
    @


Log in to reply