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

Threads and QObjects

QThread inherits QObject. It emits signals to indicate that the thread started or finished executing, and provides a few slots as well.

QThread 派生于 QObject。QThread 会发射信号通知线程启动或终止执行任务,并且也会提供槽函数使用。

More interesting is that QObjects can be used in multiple threads, emit signals that invoke slots in other threads, and post events to objects that "live" in other threads. This is possible because each thread is allowed to have its own event loop.

QObejct 可以在多线程中调用,通过信号可以调用在其它线程中的槽函数,而且可以传递事件给其它线程中的对象。这使得每个线程都有自己的事件循环成为可能。

三种情况应注意:

  • The child of a QObject must always be created in the thread where the parent was created. This implies, among other things, that you should never pass the QThread object (this) as the parent of an object created in the thread (since the QThread object itself was created in another thread).
  • QObject 的所有子类必须在创建parent对象的线程(thread)中创建。这意味着,永远不要将QThread对象作为在线程中创建的对象的parent对象(因为 QThread 对象本身是在另一个线程中创建的)。
  • Event driven objects may only be used in a single thread. Specifically, this applies to the timer mechanism and the network module. For example, you cannot start a timer or connect a socket in a thread that is not the object's thread.
  • 对于定时器机制和网络模块,事件驱动对象只能在单线程中调用。例如,不能在非对象线程的线程中启动定时器或连接套接字。
  • You must ensure that all objects created in a thread are deleted before you delete the QThread. This can be done easily by creating the objects on the stack in your run() implementation.
  • 程序员必须保证在销毁线程前销毁在线程中中创建的所有对象。要做到这一点很容易,只需在 run() 实现中在堆栈上创建对象即可。
http://www.lryc.cn/news/113887.html

相关文章:

  • Tcp是怎样进行可靠准确的传输数据包的?
  • [SWPUCTF 2022 新生赛]numgame
  • java异常机制分析
  • 浅谈Python中的内存管理 程序的内存布局
  • (具体解决方案)训练GAN深度学习的时候出现生成器loss一直上升但判别器loss趋于0
  • Redis 安装以及配置隧道连接
  • FFmpeg 使用总结
  • 出现Error: Cannot find module ‘compression-webpack-plugin‘错误
  • Elasticsearch 摄取管道 — 检测到管道的死循环
  • C# ListBox自动滚动方法
  • 使用(Ajax原理)Promise + XHR实现请求数据
  • 【HTML】<input>
  • 数据结构中一些零碎且易忘的知识点
  • 2023上半年京东烘干机行业品牌销售排行榜(京东商品数据)
  • ADS版图画封装学习笔记
  • 空地协同智能消防系统——无人机、小车协同
  • 篇二十二:解释器模式:处理语言语法
  • 【LeetCode 75】第二十一题(1207)独一无二的出现次数
  • node中使用express+mongodb实现分页查询
  • 信创优选,国产开源。Solon v2.4.2 发布
  • Java HTTP client常见库
  • 【Java基础教程】(四十四)IO篇 · 上:File类、字节流与字符流,分析字节输出流、字节输入流、字符输出流和字符输入流的区别~
  • 电商数据获取:网络爬虫还是付费数据接口?
  • 树形结构——二叉树类型
  • JavaScript对象的方法与原型链
  • Oracle入门初探---第一章 批量创建表、索引并插入测试数据
  • 全面讲解最小二乘法
  • 【阻止IE强制跳转到Edge浏览器】
  • C++/Linux项目——日志系统(简介)
  • 【Redis面试题整理一】