PDA

View Full Version : Hardware address



vajindarladdad
12th November 2009, 09:19
Hi all Experts,
I am trying to find the hardware address of my PC.
I used QNetworkInterface class but i am getting my hardware address BLANK.
Please give me a hint to do so.

spirit
12th November 2009, 09:30
how do you get an address?
show us code.

vajindarladdad
12th November 2009, 09:34
Hi ,

QNetworkInterface interface;
QString hAddress = interface.hardwareAddress();

I am new to QtNetworking , I may be wrong.
Please help .

spirit
12th November 2009, 09:35
works fine for me


foreach (const QNetworkInterface &ni, QNetworkInterface::allInterfaces())
qDebug() << ni.hardwareAddress();

vajindarladdad
12th November 2009, 09:52
I have used the code like this



QNetworkInterface interface;
QList<QNetworkInterface> networkList;
networkList = interface.allInterfaces();
for(int i=0;i<networkList.count();i++)
{
QMessageBox::information(this,"Network Interface",networkList.at(i).hardwareAddress());
}


I am getting
1) 00:00:00:00:00:00
2) 00:1E:2A:44:8A:34
3) 00:1E:2A:44:8A:34
4) 00:21:9B:0B:0A:E4
5) B2:4F:AC:1D:5B:EB
6) 56:47:C1:83:9A:52

Is this correct what i am getting ?

spirit
12th November 2009, 09:54
yes, it is.

squidge
12th November 2009, 09:57
BTW, in Qt land, foreach is easier than the equivalent structure using a standard C for loop :)

Look at spirit's code and yours. spirit's is much easier to read and follow. Why write more code when the compiler will do it for you?