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)的强大的模块化和可配置性,其设计处处透露着易用性.可复用性与易集成性.优良的 ...
随机推荐
- 设置键盘return键样式
textField.returnKeyType = UIReturnKeySend; typedef NS_ENUM(NSInteger, UIReturnKeyType) { UIReturnKey ...
- 蓝桥杯 试题 历届试题 填字母游戏 博弈+dfs剪枝
问题描述 小明经常玩 LOL 游戏上瘾,一次他想挑战K大师,不料K大师说: “我们先来玩个空格填字母的游戏,要是你不能赢我,就再别玩LOL了”. K大师在纸上画了一行n个格子,要小明和他交替往其中填入 ...
- 程序员都在用的 IDEA 插件(不断更新)
IDEA一些不错的插件分享 目录 IDEA一些不错的插件分享 插件集合 CamelCase Translation LiveEdit MarkDown Navigator Jrebel CheckSt ...
- ssserver多出口ip
环境:centos6.10-7x(虚拟机),配置好之后至少保证能上网 需求:在一台服务器上配置多ip,并实现,用哪个ip 作为代理,访问ip138.com这类的网站的时候就返回对应的ip. 实现步骤: ...
- JAVA自定义数据类型用法
一,自定义数据类型的概念: 我们就拿一部手机进行分析,它能用来做什么呢?它可以打电话,上网,聊微信等,这些就是 手机所提供的功能,也就是方法:手机也有它的特征,如颜色.尺寸大小.品牌型号等,这些 ...
- overflow:hidden的清除浮动效果
我们都知道"overflow:hidden"可以溢出隐藏,即当内容元素的高度大于其包含块的高度时,设置该属性即可把内容区域超出来的部分隐藏,使内容区域完全包含在该包含块中. 然而& ...
- golang如何优雅的编写事务代码
目录 前言 需求 烂代码示例 重构套路 一.提前返回去除if嵌套 二.goto+label提取重复代码 三.封装try-catch统一捕获panic 前言 新手程序员概有如下特点 if嵌套特别多.重复 ...
- Git常用目录
Git常用目录 // 初始化Git仓库 $ git init // 将代码添加到暂存区中 $ git add . // 将代码保存到仓库中 $ git commit -m "保存的说明&qu ...
- js解析MarkDown语法
1.问题描述: 我们使用MarkDown编辑器之后,比如我们写的MarkDown的语法是: # 一级标题 ## 二级标题 ### 三级标题 这种语法我们最终要转换成HTML的格式最终要存入数据库 ...
- 【C++】VS Code配置
0.前言 本文已配置C++环境为例,本文主要是面向刚开始接触VS Code的朋友,采用生成默认配置任务的方法,在编写本文过程中大量参考了官方文档,感兴趣的朋友可直接前往传送门. 环境: win10 + ...