当前位置: 首页 > news >正文

Qt之QHostInfo

简介

QHostInfo表示主机信息,即主机名称

常用接口

static QHostInfo fromName(const QString &name);
QString hostName() const;
QList<QHostAddress> addresses() const;

结构

QHostInfo
- QHostInfoPrivate *d_ptr
-static int lookupHostImpl(const QString &name,const QObject *receiver,QtPrivate::QSlotObjectBase *slotObj)
QHostInfoPrivate
+ QHostInfo::HostInfoError err
+ QString errorStr
+ QList<QHostAddress> addrs
+ QString hostName
+ int lookupId
+static int lookupHostImpl(const QString &name,const QObject *receiver,QtPrivate::QSlotObjectBase *slotObj, const char *member)
QHostInfoRunnable
QHostInfoResult

lookupHostImpl:用于发起查询主机地址

QHostInfoLookupManager

异步发起查询主机的管理器,在lookupHostImpl会用到

QHostInfoLookupManager
+ QHostInfoCache cache
# QList<QHostInfoRunnable*> currentLookups
# QList<QHostInfoRunnable*> postponedLookups
# QQueue<QHostInfoRunnable*> scheduledLookups
# QList<QHostInfoRunnable*> finishedLookups
# QList<int> abortedLookups
# QThreadPool threadPool
# QMutex mutex
# bool wasDeleted

其中currentLookups, postponedLookups,threadPool在多线程中才会有
全局静态变量初始化

Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager)

在管理器中的缓存中没有主机对应的主机信息时,会创建QHostInfoRunnable,调用scheduleLookup发起异步查询
在将新QHostInfoRunnable添加到scheduledLookups中,发起调度时
如果postponedLookups中的任务在currentLookups中不存在,会将postponedLookups中移动到scheduledLookups

// Transfer any postponed lookups that aren't currently running to the scheduled list, keeping already-running lookups:
    postponedLookups.erase(separate_if(postponedLookups.begin(),
                                       postponedLookups.end(),
                                       postponedLookups.begin(),
                                       std::front_inserter(scheduledLookups), // prepend! we want to finish it ASAP
                                       isAlreadyRunning).first,
                           postponedLookups.end());

如果当前正在处理列表currentLookups中已经包含提交的,会将scheduledLookups中已经在currentLookups存在的任务移动到postponedLookups中,在QHostInfoRunnable执行任务时(即run),执行完后会将postponedLookups中与当前任务相等的删除。

// Unschedule and postpone any that are currently running:
    scheduledLookups.erase(separate_if(scheduledLookups.begin(),
                                       scheduledLookups.end(),
                                       std::back_inserter(postponedLookups),
                                       scheduledLookups.begin(),
                                       isAlreadyRunning).second,
                           scheduledLookups.end());

相关文章:

  • 无法创建网站 未能找到web服务器手机版怎么用百度快照
  • 建设一个充电站需要多少钱二十条优化
  • 在黄石做政府网站百度seo排名主要看啥
  • 做销售用什么网站电商网站运营
  • 福州做网站互联网公司seo搜索引擎优化薪资水平
  • 深圳电商网络网站建设seo排名工具提升流量
  • 嵌入式AI的本地化部署的好处
  • 【51单片机】2-6【I/O口】【电动车简易防盗报警器实现】
  • 蓝桥云客--浓缩咖啡液
  • 前端精度计算:Decimal.js 基本用法与详解
  • VUE3组件综合应用(日历组件)
  • 8.5/Q1,Charls最新文章解读
  • stc8g1k08a定时读取内部1.2v电压值 vcc电压发送到串口1
  • pycharm 有智能提示,但是没法自动导包,也就是alt+enter无效果
  • JavaScript基础--03-变量的数据类型:基本数据类型和引用数据类型
  • 2025大唐杯仿真3——移动性管理
  • SQL的调优方案
  • WHAT - CSS 伪类
  • 兑换码(Java)
  • 小白速通:Verilog流水线实现及时序分析
  • Mybatis注解开发进阶之复杂的关联查询
  • Nacos注册中心AP模式核心源码分析(集群模式)
  • (一)从零开始:用 LangChain 和 ZhipuAI 搭建简单对话
  • SonarQube数据库配置
  • Flutter之页面布局一
  • Kubernetes 集群搭建(一):k8s 从环境准备到 Calico 网络插件部署(1.16版本)