I am using the following code to get the MAC ID in Qt.
main.cpp
#include <QtCore/QCoreApplication>
#include "QtNetwork/QNetworkInterface"
#include "QString"
QString getMacAddress()
{
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
{
// Return only the first non-loopback MAC Address
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
return interface.hardwareAddress();
QString text = interface.hardwareAddress();
qDebug() << text;
}
return QString();
}
int main(int argc, char *argv[])
{
getMacAddress();
QCoreApplication a(argc, argv);
return a.exec();
}
I am getting nothing in Console? Guide me thanks...
CONFIG += console
in your .pro? – LaryngealQT += core QT += network QT -= gui TARGET = qmacid CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
I presume there is some problem in getMacAddress() function. – Rhotacismreturn interface.hardwareAddress();
so perhaps it returns there without printing anything. – Laryngeal