• 4516阅读
  • 2回复

Qt4中有没有用于将域名解析成IP的类? [复制链接]

上一主题 下一主题
离线tangooricha
 

只看楼主 倒序阅读 楼主  发表于: 2009-07-14
— 本帖被 XChinux 执行加亮操作(2009-07-14) —
因为要写的一个程序中需要有一个类似nslookup的功能,就是将输入的域名转换为IP并显示出来。由于不想使用 C函数来实现该功能,所以想问一下Qt4中有没有用于将域名解析成IP的类?
离线280923299
只看该作者 1楼 发表于: 2009-07-14
QHostInfo

Detailed Description

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.

To look up a host's IP addresses asynchronously, call lookupHost(), which takes the host name or IP address, a receiver object, and a slot signature as arguments and returns an ID. You can abort the lookup by calling abortHostLookup() with the lookup ID.

Example:

// To find the IP address of qtsoftware.com
QHostInfo::lookupHost("qtsoftware.com",
                       this, SLOT(printResults(QHostInfo)));

// To find the host name for 4.2.2.1
QHostInfo::lookupHost("4.2.2.1",
                       this, SLOT(printResults(QHostInfo)));
离线tangooricha

只看该作者 2楼 发表于: 2009-07-14
Thanks very much!
快速回复
限100 字节
 
上一个 下一个