PDA

View Full Version : Using QHostInfo to get host name from an IP



guidupas
11th February 2014, 16:52
Hi all!

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

This is my code:

bool rede::verificaIP(QString ip)
{
info.setAddresses();
QHostInfo info = QHostInfo::fromName(ip);

qDebug() << "IP:" << info.hostName() << info.addresses();

return false;
}

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.

sakya
12th February 2014, 11:03
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 (http://qt-project.org/doc/qt-5/qhostinfo.html#lookupHost)

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

guidupas
12th February 2014, 12:16
Yes, its in the QhostInfo documentation, but in my network it does not happen. Can Anyone help my please. Thanks a lot

anda_skoa
12th February 2014, 12:39
What is the correct hostname?

Does the hostname correctly resolve to the address?

Cheers,
_