Reputation: 79
i want a method to get a QStringList of IPs associated to an URL, i have those tow methods and they work perfectly but i want all of this is on single method like this: QStringList DNSResolver(QString host);
void Object::test()
{
QHostInfo::lookupHost("www.google.com",this, SLOT(lookedUp(QHostInfo)));
}
void Object::lookedUp(const QHostInfo &host)
{
if (host.error() != QHostInfo::NoError) {
qDebug() << "Lookup failed:" << host.errorString();
}
foreach (const QHostAddress &address, host.addresses())
{
qDebug() << "Lookup success:" << address.toString();
}
}
Upvotes: 2
Views: 2195
Reputation: 32645
You can use QHostInfo::fromName ( const QString & name )
which blocks during the lookup :
QStringList DNSResolver(QString host)
{
QHostInfo hostInfo;
QHostInfo returnedHost = hostInfo.fromName(host);
if (returnedHost.error() != QHostInfo::NoError) {
qDebug() << "Lookup failed:" << returnedHost.errorString();
}
QStringList list;
foreach (const QHostAddress &address, returnedHost.addresses())
{
list<<address.toString();
}
return list;
}
Upvotes: 3