Results 1 to 4 of 4

Thread: Using QHostInfo to get host name from an IP

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Using QHostInfo to get host name from an IP

    Hi all!

    I am trying to get the host name from a IP inside my LAN using QHostInfo.

    This is my code:
    Qt Code:
    1. bool rede::verificaIP(QString ip)
    2. {
    3. info.setAddresses();
    4. QHostInfo info = QHostInfo::fromName(ip);
    5.  
    6. qDebug() << "IP:" << info.hostName() << info.addresses();
    7.  
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 

    The ip parameter is 192.168.1.91

    But the result is:
    IP: "192.168.1.91" (QHostAddress("192.168.1.91") )

    The function does not returns the host name

    Can anyone help me?

    Thanks a lot.

  2. #2
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Using QHostInfo to get host name from an IP

    fromName retrieve the IP address from name
    Looks up the IP address(es) for the given host name.
    To get the host name from a IP address you need to use QHostInfo::lookupHost

    EDIT: I made a test now and in my network also fromName returns the host name from the IP...

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using QHostInfo to get host name from an IP

    Yes, its in the QhostInfo documentation, but in my network it does not happen. Can Anyone help my please. Thanks a lot

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QHostInfo to get host name from an IP

    What is the correct hostname?

    Does the hostname correctly resolve to the address?

    Cheers,
    _

Similar Threads

  1. QHostInfo::lookupHost
    By matteo.ceruti in forum Qt Programming
    Replies: 0
    Last Post: 30th January 2012, 15:54
  2. QHostInfo - Unknown Error
    By alurchi in forum Qt Programming
    Replies: 7
    Last Post: 17th May 2011, 11:59
  3. Replies: 1
    Last Post: 17th July 2010, 12:02
  4. Hostlookup using QHostInfo
    By doggrant in forum Qt Programming
    Replies: 7
    Last Post: 26th January 2010, 13:58
  5. QHostInfo usefullness
    By baray98 in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2007, 14:07

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.