PyQt中QThread多线程的正确用法【待完善】
先贴几篇有意思的讨论
https://www.qt.io/blog/2010/06/17/youre-doing-it-wrong#commento-login-box-container
https://www.qt.io/blog/2006/12/04/threading-without-the-headache
https://woboq.com/blog/qthread-you-were-not-doing-so-wrong.html
http://blog.debao.me/2013/08/how-to-use-qthread-in-the-right-way-part-1/
https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
https://blog.csdn.net/czyt1988/article/details/71194457
有篇国内:https://blog.csdn.net/lynfam/article/details/7081757
https://blog.csdn.net/bladeandmaster88/article/details/51802491
http://blog.sina.com.cn/s/blog_a6fb6cc90102vs8z.html
https://blog.csdn.net/dbzhang800/article/details/6882981
https://blog.csdn.net/dbzhang800/article/details/6889291
https://blog.csdn.net/czyt1988/article/details/64441443
https://stackoverflow.com/questions/16879971/example-of-the-right-way-to-use-qthread-in-pyqt
https://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt
PYTHON:
https://stackoverflow.com/questions/20324804/how-to-use-qthread-correctly-in-pyqt-with-movetothread
So, the conclusion is:
1. Don't read Qt 4.6 docs, it is wrong as it says "To create your own threads, subclass QThread and reimplement run()." http://doc.qt.nokia.com/4.6...
- Don't read the given "best resource", it is also wrong, because it also subclasses QThread: "...just a small amount of work: subclass QThread and reimplement run().." http://labs.trolltech.com/b...
The correct answer is in the shortest blog given in the comments: http://labs.trolltech.com/b...
Here's a shortened snippet from it for those who don't want to dig into the tarball:
class Producer : public QObject
{
Q_OBJECT
public slots:
void produce() { ...emit produced(&data)...emit finished().. }
signals:
void produced(QByteArray *data);
void finished();
};
class Consumer : public QObject
{
Q_OBJECT
public slots:
void consume(QByteArray *data) { ...emit consumed()...emit finished().. }
signals:
void consumed();
void finished();
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
// create the producer and consumer and plug them together
Producer producer;
Consumer consumer;
producer.connect(&consumer, SIGNAL(consumed()), SLOT(produce()));
consumer.connect(&producer, SIGNAL(produced(QByteArray *)), SLOT(consume(QByteArray *)));
// they both get their own thread
QThread producerThread;
producer.moveToThread(&producerThread);
QThread consumerThread;
consumer.moveToThread(&consumerThread);
// start producing once the producer's thread has started
producer.connect(&producerThread, SIGNAL(started()), SLOT(produce()));
// when the consumer is done, it stops its thread
consumerThread.connect(&consumer, SIGNAL(finished()), SLOT(quit()));
// when consumerThread is done, it stops the producerThread
producerThread.connect(&consumerThread, SIGNAL(finished()), SLOT(quit()));
// when producerThread is done, it quits the application
app.connect(&producerThread, SIGNAL(finished()), SLOT(quit()));
// go!
producerThread.start();
consumerThread.start();
return app.exec();
}
https://nikolak.com/pyqt-threading-tutorial/
https://blog.csdn.net/weixin_34348805/article/details/90525817
https://yq.aliyun.com/articles/119876?scm=20140722.184.2.173
PyQt中QThread多线程的正确用法【待完善】的更多相关文章
- 转载~kxcfzyk:Linux C语言多线程库Pthread中条件变量的的正确用法逐步详解
Linux C语言多线程库Pthread中条件变量的的正确用法逐步详解 多线程c语言linuxsemaphore条件变量 (本文的读者定位是了解Pthread常用多线程API和Pthread互斥锁 ...
- Spring MVC中Session的正确用法<转>
Spring MVC是个非常优秀的框架,其优秀之处继承自Spring本身依赖注入(Dependency Injection)的强大的模块化和可配置性,其设计处处透露着易用性.可复用性与易集成性.优良的 ...
- C#中dynamic的正确用法
C#中dynamic的正确用法 http://www.cnblogs.com/qiuweiguo/archive/2011/08/03/2125982.html dynamic是FrameWork4 ...
- 【转】Spring MVC中Session的正确用法之我见
Spring MVC是个非常优秀的框架,其优秀之处继承自Spring本身依赖注入(Dependency Injection)的强大的模块化和可配置性,其设计处处透露着易用性.可复用性与易集成性.优良的 ...
- C#中dynamic的正确用法 以及 typeof(DynamicSample).GetMethod("Add");
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- 【转】改善C#程序的建议2:C#中dynamic的正确用法 空间
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- C#中dynamic、ExpandoObject 的正确用法
原文地址:http://www.cnblogs.com/qiuweiguo/archive/2011/08/03/2125982.html dynamic是FrameWork4.0的新特性.dynam ...
- C#中dynamic的正确用法【转】
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- Spring MVC中Session的正确用法之我见
Spring MVC是个非常优秀的框架,其优秀之处继承自Spring本身依赖注入(Dependency Injection)的强大的模块化和可配置性,其设计处处透露着易用性.可复用性与易集成性.优良的 ...
随机推荐
- 【Mac】anaconda自定义channels
1.查看channels conda config --show channels 输出 channels: - defaults 2.添加channels conda config --add ch ...
- afert和b的伪类画三角形
/* 提示信息 */ .content-tishi{ width: 6.93rem; margin: 0 auto; background: #e9eaea; display: flex; flex- ...
- Web前端:1、HTML&CSS概述及结构
万维网联盟(World Wide Web Consortium)简称W3C,专门为了定义网页相关的标准而成立,如网页中的HTML.CSS.DOM.HTTP.XML等标准. 根据W3C标准,一个网页主要 ...
- Python的多线程锁跟队列
一.互斥锁: 1.线程同步能够保证多个线程安全访问竞争资源,最简单的同步机制是引入互斥锁. 2.互斥锁为资源引入一个状态:锁定.非锁定 3.某个线程要更改共享数据是,先将其锁定.此时资源的状态为锁定, ...
- 【C++】常见易犯错误之数值类型取值溢出与截断(3)
0. 前言 本节是“[C++]常见易犯错误之数值类型取值溢出与截断(1)” 的补充,主要探讨浮点型的取值溢出. 1. 相关知识 (1) 浮点型数据取值范围如下: 单精度型 float 3.4 * 1 ...
- [Unity2d系列教程] 002.引用外部DLL - C
上一篇我们学习了Unity调用C#生成的外部DLL,但是有时候我们需要访问底层,不能不适用C生成的DLL.下面就让我们一起学习下,C如何生成. 1.创建一个C的控制台程序 2.点击确定->点击下 ...
- [Objective-C] 021 KVC、KVO
写过C#的都知道C#通过反射读写一个对象的属性特别方便,可以利用字符串的方式去动态控制一个对象.其实在ObjC中,我们可以更高级点,根本不必进行任何操作就可以进行属性的动态读写,这种方式就是Key V ...
- [代码片段-C#]工具代码片段 及 版本信息等
标题: [SD.TEAM]XXXX 公司: 宝宝巴士(福建)网络科技有限公司 商标: 宝宝巴士 版权: © Babybus SD.Team 版权+作者(简): © Babybus SD.Team - ...
- [批处理教程之Shell]002.Linux 常用命令大全
这一次收集的是比较基础的 Linux 命令,其实 Linux 命令未必每个都要记住,只要在用到时能查阅到需要的命令的用法. 系统信息 *.显示机器的处理器架构(1)arch *.显示机器的处理器架构( ...
- FHQ-Treap学习笔记
平衡树与FHQ-Treap 平衡树(即平衡二叉搜索树),是通过一系列玄学操作让二叉搜索树(BST)处于较平衡的状态,防止在某些数据下退化(BST在插入值单调时,树形不平衡,单次会退化成 \(\math ...