Results 1 to 8 of 8

Thread: filter QNetworkInterface::hardwareAddress()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: filter QNetworkInterface::hardwareAddress()

    interfaceFromName() expects interface name returned by QNetworkInterface::name() (ie "{D6637618-7E2B-466B-B02B-C35A1FA9118F}") not QNetworkInterface::humanReadableName().

    So, if you want to find interface by human readable name you have to loop through the interfaces and find it yourself.

    In the end it's only few lines of code:
    Qt Code:
    1. QList< QNetworkInterface > it = QNetworkInterface::allInterfaces();
    2. for( int i = 0; i < it.size(); ++i )
    3. {
    4. if( it.at( i ).humanReadableName() == "Local Area Connection" )
    5. {
    6. qDebug() << it.at( i ).hardwareAddress();
    7. break;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Spitfire for this useful post:

    prophet0 (12th April 2012)

  3. #2
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: filter QNetworkInterface::hardwareAddress()

    That works perfectly thanks very much

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: filter QNetworkInterface::hardwareAddress()

    Quote Originally Posted by Spitfire View Post
    interfaceFromName() expects interface name returned by QNetworkInterface::name() (ie "{D6637618-7E2B-466B-B02B-C35A1FA9118F}") not QNetworkInterface::humanReadableName().
    Is that some Windows perversion? QNetworkInterface::interfaceFromName() works perfectly fine with "eth0", i.e. the same as the humanReadableName(), on Linux.

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: filter QNetworkInterface::hardwareAddress()

    On linux both are the same but Microsoft invented 'better' way, obviously

Similar Threads

  1. QNetworkInterface::allAddresses() crash
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 15th October 2014, 03:06
  2. hardwareAddress(es)
    By uygar in forum Qt Programming
    Replies: 13
    Last Post: 17th June 2009, 10:42
  3. QNetworkInterface get IP
    By pdoria in forum Newbie
    Replies: 2
    Last Post: 3rd January 2008, 08:48
  4. problem w/qnetworkinterface.h
    By ber_44 in forum Installation and Deployment
    Replies: 2
    Last Post: 13th April 2007, 11:38
  5. Discovery ifdown/ifup on all OS; by QNetworkInterface
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2007, 12:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.