I've added a simple browser page to my application using the demo code in Qt 4.8 as a base: [QTDIR]\demos\browser

This works fine in Windows, but when I rebuild the app and try it on my embedded Linux device it fails. While experimenting I found I could load www.google.com by resolving the IP address and using that instead. I added the following code to my app:

QHostInfo hostInfo = QHostInfo::fromName(m_url);
if (hostInfo.error() != QHostInfo::NoError)
{
    qDebug() << "Lookup failed:" << hostInfo.errorString();
}
foreach (QHostAddress hostAdd, hostInfo.addresses())
{
    qDebug() << "Found address:" << hostAdd.toString();
}

This outputs the error "Temporary failure in name resolution". So on the device I've tried:

  1. Checked /etc/resolv.conf - looks good.
  2. Checked my gateway shows up in "route -n" - looks good.
  3. Tried "ping 8.8.8.8" - works fine.
  4. Tried "nslookup www.google.com" - works fine.
  5. Tried "wget http://www.google.com" - correctly loads index.html.

I can only imagine that Qt is using a different method to resolve DNS addresses but I have no idea what it could be.

有帮助吗?

解决方案

It turns out that "Temporary failure in name resolution" is the error EAI_AGAIN, which getaddrinfo() returns when it doesn't really know what the problem is. It was failing because I was running nslookup as root but the application was running under a user account, and by mistake only root had read permission for /etc/resolv.conf. Once I did a chmod everything worked.

To fix this permanently we added a chmod to /usr/libexec/udhcpc.sh so the permission on /etc/resolve.conf is set correctly when it's created.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top