QT  - 讨论区

标题:Qt Tutorial 017:使用QHostInfo模块查询DNS

2014年03月07日 星期五 09:29

QHostInfo模块提供了根据域名查询IP地址的API,并同时提供阻塞式和异步式两种API。

The QHostInfo class provides static functions for host name lookups.

QHostInfo uses the lookup mechanisms provided by the operating system to find the IP address(es) associated with a host name, or the host name associated with an IP address. The class provides two static convenience functions: one that works asynchronously and emits a signal once the host is found, and one that blocks and returns a QHostInfo object.

示例代码如下:

#include <QCoreApplication>
#include <QtCore>
#include <QtNetwork>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    auto info=QHostInfo::fromName("www.163.com");
    auto ips=info.addresses();
    for(auto ip : ips){
        qDebug() << ip.toString();
    }
    return a.exec();
}

参考资料:

http://qt-project.org/doc/qt-5/QHostInfo.html

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号