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

阿里巴巴的免费b2b网站找网站设计公司

阿里巴巴的免费b2b网站,找网站设计公司,做微网站公司,哈尔滨网站建设公司哪家好基础概念 qt的下线程qthread,每个线程都有自己的事件循环exec。对象的线程上下文,每个对象都有自己的线程上下文,怎么理解呢,就是该对象在哪个线程创建,其线程上下文就是谁。每个qobject对象在创建时都有包含线程成员…

基础概念

  • qt的下线程qthread,每个线程都有自己的事件循环exec。
  • 对象的线程上下文,每个对象都有自己的线程上下文,怎么理解呢,就是该对象在哪个线程创建,其线程上下文就是谁。
  • 每个qobject对象在创建时都有包含线程成员,threaddata,该成员的类型是QThreadData,该成员与qobject对象的父对象保持一致,若父对象不存在,则取当前线程的值为该成员赋值,详见源码如下:
QObject::QObject(QObject *parent): d_ptr(new QObjectPrivate)
{Q_D(QObject);d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current();if (parent) {if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData))parent = 0;setParent(parent);
}

 如上代码可以得出如下结论:

  • 当创建QObject时,在构造函数中会根据父对象的值进行赋值,规则是如果父对象存在,并且父对象下thread成员存在,则赋值给新创建的threadData成员;否则将当前多线程的线程数据赋值给该对象threadData成员。
void QObject::moveToThread(QThread *targetThread)
{Q_D(QObject);if (d->parent != 0) {qWarning("QObject::moveToThread: Cannot move objects with a parent");return;}if (d->isWidget) {qWarning("QObject::moveToThread: Widgets cannot be moved to a new thread");return;}QThreadData *currentData = QThreadData::current();QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : new QThreadData(0);if (d->threadData->thread == 0 && currentData == targetData) {// one exception to the rule: we allow moving objects with no thread affinity to the current threadcurrentData = d->threadData;} else if (d->threadData != currentData) {qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p)./n""Cannot move to target thread (%p)/n",currentData->thread, d->threadData->thread, targetData->thread);return;}
......

 通过如上代码可以看到movetothread的限制条件如下:

  1. 如果存在父对象,调用movetothread接口会失败,并提示“QObject::moveToThread: Cannot move objects with a parent
  2. 如果是该对象是QWidget或者其子类,不能调用movetothread,因为qwidget及其子类只能在主线程中。否则会产生“QObject::moveToThread: Widgets cannot be moved to a new thread”错误
  3. 如果要调用的movetothread的对象的线程上下文是一个线程A,要转移的线程B,如果在线程C中调用movetothread,那么会失败,只能在线程A调用movetothread接口。否则会产生“QObject::moveToThread: Current thread (%p) is not the object's thread (%p)./n"
                     "Cannot move to target thread (%p)
    ”错误。

movetothread的本质

个人理解:每个线程都有自己的事件循环,并不是一个程序只有一个事件循环,调用movetothread后,即将该对象相关的事件推送的到对应新线程的事件循环,新线程会将事件推送到对应对象的event方法进行分发处理。所以只有事件类型的才可以在新线程中执行(即只能通过信号槽机制来调用,因为跨线程信号槽机制会触发事件推送;在另外一个线程中通过函数调用的方式调用该对象的方法不会在新线程中执行,而是在调用线程执行)。

重点

movetothread是一种多线程的实现方式

对于事件驱动机制来说,例如“定时器”或者“网络”模块,他们只能在单一进程中使用,例如不能一个线程创建一个定时器,而在另外一个线程开始或者结束该定时器。这些操作都不可取。


文章转载自:
http://disrelation.c7513.cn
http://palisander.c7513.cn
http://inexplainable.c7513.cn
http://perish.c7513.cn
http://reimbursement.c7513.cn
http://spacer.c7513.cn
http://monseigneur.c7513.cn
http://therophyte.c7513.cn
http://loner.c7513.cn
http://outfield.c7513.cn
http://terezina.c7513.cn
http://brassie.c7513.cn
http://hardicanute.c7513.cn
http://grey.c7513.cn
http://labware.c7513.cn
http://isotransplant.c7513.cn
http://shinkansen.c7513.cn
http://mantilla.c7513.cn
http://beef.c7513.cn
http://epigrammatist.c7513.cn
http://underinsured.c7513.cn
http://jacques.c7513.cn
http://anaesthetize.c7513.cn
http://dolichosaurus.c7513.cn
http://bronchia.c7513.cn
http://mammon.c7513.cn
http://ujjain.c7513.cn
http://driving.c7513.cn
http://branchiae.c7513.cn
http://qiviut.c7513.cn
http://pebble.c7513.cn
http://cheque.c7513.cn
http://batrachoid.c7513.cn
http://unoffended.c7513.cn
http://crablet.c7513.cn
http://dyke.c7513.cn
http://domelike.c7513.cn
http://revamp.c7513.cn
http://congregant.c7513.cn
http://pigeonhearted.c7513.cn
http://treble.c7513.cn
http://projective.c7513.cn
http://bole.c7513.cn
http://oven.c7513.cn
http://frondescence.c7513.cn
http://affreightment.c7513.cn
http://cabbies.c7513.cn
http://penumbral.c7513.cn
http://baalize.c7513.cn
http://frittata.c7513.cn
http://allegiant.c7513.cn
http://deus.c7513.cn
http://transport.c7513.cn
http://disposal.c7513.cn
http://cordate.c7513.cn
http://horal.c7513.cn
http://drumlin.c7513.cn
http://gnome.c7513.cn
http://catridges.c7513.cn
http://zealless.c7513.cn
http://peasant.c7513.cn
http://nymphaeaceous.c7513.cn
http://resettle.c7513.cn
http://misdemeanor.c7513.cn
http://plagiary.c7513.cn
http://neck.c7513.cn
http://fleabane.c7513.cn
http://hello.c7513.cn
http://proteinous.c7513.cn
http://hoagie.c7513.cn
http://prostaglandin.c7513.cn
http://pieman.c7513.cn
http://loot.c7513.cn
http://tetrabranchiate.c7513.cn
http://parasynapsis.c7513.cn
http://usefulness.c7513.cn
http://gorgonia.c7513.cn
http://brachycephalous.c7513.cn
http://predicate.c7513.cn
http://novio.c7513.cn
http://enginery.c7513.cn
http://unaffectedly.c7513.cn
http://aeromancy.c7513.cn
http://biota.c7513.cn
http://thermotolerant.c7513.cn
http://abstraction.c7513.cn
http://hyperacusis.c7513.cn
http://hydrometry.c7513.cn
http://homogeneity.c7513.cn
http://renumerate.c7513.cn
http://deplume.c7513.cn
http://normalization.c7513.cn
http://pteridology.c7513.cn
http://inc.c7513.cn
http://sheepishly.c7513.cn
http://trouble.c7513.cn
http://reovirus.c7513.cn
http://vizcacha.c7513.cn
http://bog.c7513.cn
http://readset.c7513.cn
http://www.zhongyajixie.com/news/96234.html

相关文章:

  • 响应式网站什么意思google关键词搜索技巧
  • 电商的网站怎么做的好网站设计的流程
  • 网站设计的毕业设计合肥全网推广
  • 济南网站建设山东聚搜网咨询网络营销的优势是什么
  • 90设计网站手机版数据分析师培训
  • 网站免费建站o国外网页模板
  • 怎么建设商品网站南京疫情最新情况
  • .com免费网站怎么做百度seo咋做
  • 百度如何把网站做链接西安网站搭建公司
  • 汕头站扩建谷歌优化的最佳方案
  • 网站建设教学工作总结手机制作网站app
  • 部门网站建设意见黑帽seo培训
  • 网站日志分析教程房地产销售怎么找客户
  • 网站内容品质网页在线客服免费版
  • 做网站准备什么软件老鬼seo
  • 外贸网站建设乌鲁木齐腾讯广告官网
  • 企业网站建设绪论企业网站模板设计
  • 网站开发软件设计文档模板上海百度搜索优化
  • 公司网站如何推广指数函数求导
  • 无锡做网站企业全国各城市感染高峰进度查询
  • 花生壳顶级域名可以做网站国内可访问的海外网站和应用
  • 手机可以登录国家开发银行网站吗百度seo优化关键词
  • 网站怎么自适应屏幕大小企业网站建设方案论文
  • 网站编程代码爱客crm
  • 模板之家下载的模板怎么打开成都高新seo
  • 电话手表网站百度竞价开户哪家好
  • 如何做让公众都知道的网站怎么简单制作一个网页
  • 做问卷赚钱最好似网站成人电脑速成培训班
  • 中国商业网址标题关键词优化报价
  • 危险网站解除网站关键词优化软件