博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
qt中域名解析的方法
阅读量:3947 次
发布时间:2019-05-24

本文共 1201 字,大约阅读时间需要 4 分钟。

               

本文博客链接:,作者:jdh,转载请注明.

qt中提供了可以实现域名解析功能的类QHostInfo,这个类解析域名提供两种机制,一种是阻塞式,一种是非阻塞信号槽机制,下面介绍第二种机制的实现方法。

qt的帮助中给出了这个类的例子:

QHostInfo::lookupHost("www.kde.org",this, SLOT(lookedUp(QHostInfo)));//当解析成功域名后,会调用lookedUp槽函数void MyWidget::lookedUp(const QHostInfo &host) {     if (host.error() != QHostInfo::NoError) {         qDebug() << "Lookup failed:" << host.errorString();         return;     }     foreach (QHostAddress address, host.addresses())         qDebug() << "Found address:" << address.toString(); }

仿照这个例子,我做了google域名的解析测试:

QHostInfo::lookupHost("www.google.com",this,SLOT(slot_get_ip(QHostInfo)));void test::slot_get_ip(QHostInfo host_info){    if (host_info.error() != QHostInfo::NoError)    {         qDebug() << "Lookup failed:" << host_info.errorString();         return;    }    for (int i = 0;i < host_info.addresses().size();i++)    {         qDebug() << "Found address:" << host_info.addresses()[i].toString() << endl;    }}

在调试窗口可以看到解析结果:

Found address: "64.233.183.106" Found address: "64.233.183.147" Found address: "64.233.183.99" Found address: "64.233.183.103" Found address: "64.233.183.104" Found address: "64.233.183.105"

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!

你可能感兴趣的文章
Displaying Card Flip Animations 显示卡片翻转动画
查看>>
Zooming a View 缩放视图
查看>>
Animating Layout Changes 动画布局的更改
查看>>
Controlling Your App’s Volume and Playback 控制应用程序的音量和播放
查看>>
Managing Audio Focus 管理音频焦点
查看>>
Dealing with Audio Output Hardware 处理音频输出硬件设备
查看>>
Monitoring the Battery Level and Charging State 监测电池电量和充电状态
查看>>
Determining and Monitoring the Docking State and Type 判断并监测设备的停驻状态与类型
查看>>
Determining and Monitoring the Connectivity Status 根据网络连接状况去省电
查看>>
Manipulating Broadcast Receivers On Demand 按需操控广播接收
查看>>
Creating a View Class 创建一个视图类
查看>>
Custom Drawing 自定义绘制
查看>>
Making the View Interactive 视图互动
查看>>
Optimizing the View 优化视图
查看>>
Setting Up the Search Interface 设置搜索界面
查看>>
Storing and Searching for Data 数据存储和搜索
查看>>
Remaining Backward Compatible 保持向后兼容
查看>>
Remembering Your User 记住你的用户
查看>>
Authenticating to OAuth2 Services 验证OAuth2服务
查看>>
Creating a Custom Account Type 创建自定义帐户类型
查看>>