当前位置:网站首页>Qt多线程实例与connect第五个参数[通俗易懂]
Qt多线程实例与connect第五个参数[通俗易懂]
2022-07-23 15:13:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Qt是一个GUI框架,在GUI程序中,主线程也叫GUI线程,因为它是唯一被允许执行GUI相关操作的线程。对于一些耗时的操作,如果放在主线程中,就是出现界面无法响应的问题。
解决方法一:在处理耗时操作中频繁调用QApplication::processEvents()。这个函数告诉Qt去处理那些还没有被处理的各类事件,然后再把控制权返还给调用者。
QElapsedTimer et;
et.start();
while(et.elapsed()<300)
QCoreApplication::processEvents(); 解决方法二:采用多线程,将需要处理的后台数据放入子线程,为了能够跨线程调用,一种方法是使用类似线程锁对线程进行保护,另外一种方法使用Qt的信号槽机制。Qt的信号槽机制采用connect函数进行连接,connect函数其实是有第五个参数的,但这个参数往往在多线程调用中才会用到:
connect(Sender,SIGNAL(signal),Receiver,SLOT(slot),Qt::DirectConnection); 第五个参数代表槽函数在哪个线程中执行 : 1)自动连接(AutoConnection),默认的连接方式,如果信号与槽,也就是发送者与接受者在同一线程,等同于直接连接;如果发送者与接受者处在不同线程,等同于队列连接。 2)直接连接(DirectConnection),当信号发射时,槽函
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126660.html原文链接:https://javaforall.cn
边栏推荐
- Aike AI frontier promotion (7.23)
- Element content must consist of character data or tags with correct format
- el-input使用
- Emgu cv3+c # image processing (IV): use emgucv to obtain camera and read video
- 为啥一问 JVM 就 懵B ???
- Debug:形参带有Const修饰符号需要注意的地方
- vim 笔记
- 面试官:如何用 Redis 实现分布式锁?
- idea debug常用操作
- Transfer business append log (transaction propagation behavior)
猜你喜欢

Analyze optimism replay contract address attack events

@Will multiple bean instances be created by multiple method calls of bean annotations
不掌握这些坑,你敢用BigDecimal吗?
Do you dare to use BigDecimal without mastering these pits?

Kv260 single board PS control setting IIC switch chip
![[operation] Yan Yi (Internet new technology operation)](/img/7a/38c7a9ed79e626506de067f360384c.png)
[operation] Yan Yi (Internet new technology operation)

Aike AI frontier promotion (7.23)

5秒到1秒,记一次效果“非常”显著的性能优化

Trust finds the maximum value in the array

el-input使用
随机推荐
Tapdata 与优炫数据库完成产品兼容性互认证
Record the range of data that MySQL update will lock
使用moment获取当天日期与下一天
IDEA Download Sources报错 Connection refused的解决方法
[operation] Yan Yi (Internet new technology operation)
LeetCode_ Dynamic programming_ Medium_ 120. Triangle minimum path sum
Trust finds the maximum value in the array
【作业】研一(互联网新技术作业)
训练和测试的loss不下降,并且精度超低
MongoDB分组取每组中一条数据
分布式事务解决方案
MySQL executes alter table XX add column with duplicate entry error
Console calculator developed based on C language
Rust中的函数function与方法method的区别
Interviewer: what is the possible reason for the slow query of MySQL database besides the index problem?
Trust counts the number of occurrences of words in the file
网页返回更新
tp&smarty使用日记
vim 笔记
leetcode刷题:动态规划04(不同路径)