PDA

View Full Version : QHostInfo - Unknown Error



alurchi
16th May 2011, 15:38
Hi folks,

I have written a very simple Application that uses QHostInfo.

If I use QHostInfo::lookupHost(...) and enter an IP-address it seems to work fine.
But if I enter a name, the adresses-list is always empty and the errorString says "Unknown error" - every time (except when I enter an invalid address).

any Ideas?



void network::slotRequest()
{
hostName = ui.lineEdit->text();
QHostInfo::lookupHost(hostName, this, SLOT(slotShowResults(QHostInfo)));
}


void network::slotShowResults(QHostInfo info)
{
if(info.addresses().isEmpty())
{
ui.labelOutput->setText(info.errorString());
}
else
{
ui.labelOutput->setText(info.addresses().first().toString());
}
}

wysota
17th May 2011, 01:25
Can your machine resolve hostnames properly? What happens if you try to resolve a hostname manually from within a terminal?

alurchi
17th May 2011, 09:55
Pinging a website via the windows console works properly... :confused:

wysota
17th May 2011, 11:38
Try writing a simple application that calls gethostbyname() and see if it works.

alurchi
17th May 2011, 12:35
ok, so I took the gethostbyname() example from the msdn page and compiled it.
It is actually able to give me IPs for domain names...

wysota
17th May 2011, 12:55
On Windows QHostInfo uses either gethostbyname() or (preferrably) getaddrinfo() and the situation you have ("Unknown error" string) can happen only if getaddrinfo() returns an error different than WSAHOST_NOT_FOUND or WSANO_DATA or when gethostbyname() returns an error different than host not found (11001). Check if getaddrinfo() works for you as you did with gethostbyname().

What happens if you pass "localhost" as the host name?

alurchi
17th May 2011, 12:56
so this is interesting: My project folder is in a network folder (The gethostbyname() example works in the networkfolder).
When I start my program on a local drive it works...
What could be the explanation for that?

wysota
17th May 2011, 12:59
No idea, ask uncle Bill :)