Results 1 to 3 of 3

Thread: QHostInfo IP Detection under Vista

  1. #1
    Join Date
    Jun 2006
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QHostInfo IP Detection under Vista

    Next code is woring well under all win system before vista.
    Qt Code:
    1. QString ipAddress;
    2. QHostInfo info = QHostInfo::fromName( QHostInfo::localHostName() );
    3. QList<QHostAddress> listAddr= info.addresses();
    4. ipAddress = listAddr.first().toString();
    To copy to clipboard, switch view to plain text mode 
    Under vista this code giving IPv6 addr. (FE80:0:0:0:4B1:.....)
    Any ideas?
    Last edited by marcel; 4th May 2008 at 10:23. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHostInfo IP Detection under Vista

    Try to convert it to ipv4 with QHostInfo::toIPb4Address.
    You should construct a new QHostInfo from that value.

    To make it work on both vista and xp you can test the protocol with QHostInfo::protocol and make the necessary conversion, if necessary.

  3. #3
    Join Date
    Jun 2006
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHostInfo IP Detection under Vista

    Yes. Solved using protocol() method
    Qt Code:
    1. QHostInfo info = QHostInfo::fromName( QHostInfo::localHostName() );
    2. QList<QHostAddress> listAddr= info.addresses();
    3. for( int i = 0; i < listAddr.size(); i ++ )
    4. {
    5. if( listAddr.at(i).protocol() == QAbstractSocket::IPv4Protocol )
    6. {
    7. ipAddress = listAddr.at(i).toString();
    8. break;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcel; 4th May 2008 at 16:09.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.