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(); }
参考资料:
Zeuux © 2024
京ICP备05028076号