欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > Qt之QHostInfo

Qt之QHostInfo

2025/4/8 23:12:58 来源:https://blog.csdn.net/wuli2496/article/details/147014289  浏览:    关键词: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 ASAPisAlreadyRunning).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());

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词