当前位置:网站首页>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
边栏推荐
- VIM notes
- Trust guessing numbers game
- ContextLoaderListener vs DispatcherServlet
- Redis数据丢失问题
- mysql字段修改
- Literature learning (part100) -- an introduction to autoencoders
- Food safety | attention to smoking food, do you know this knowledge
- WSUS can patch MySQL Middleware_ Join the WSUS patch server and download the patch
- 工作常用操作
- CreateFileMapping 函数「建议收藏」
猜你喜欢

Leetcode skimming: dynamic planning 04 (different paths)

leetcode刷题:动态规划05(不同路径 II)

As a background developer, you must know two kinds of filters

使用moment获取当天日期与下一天

leetcode刷题:动态规划04(不同路径)

机器学习(9)——特征工程(3)(补充)

The larger the convolution kernel, the stronger the performance? An interpretation of replknet model

USB Type-C PD CC逻辑芯片中的角色定义

Redis distributed lock, it's really impossible without it

xlinx pcie xvc
随机推荐
Sublime text tips
vim 笔记
数智化时代文旅遇新机?中国移动咪咕造 “元宇宙第一岛”
不掌握这些坑,你敢用BigDecimal吗?
js工具 cecp
为啥一问 JVM 就 懵B ???
curl命令详解[通俗易懂]
MongoDB分组取每组中一条数据
From 5 seconds to 1 second, remember the performance optimization with "very" significant effect once
curl get&post
Console calculator developed based on C language
Solutions to sap Hana database backup failure
Données chronologiques dans l'Internet industriel des objets
Tapdata 与优炫数据库完成产品兼容性互认证
LeetCode_动态规划_中等_120.三角形最小路径和
Create a flow using flow builder in kotlin
Redis distributed lock, it's really impossible without it
几何参数化重构
Why do you get confused when you ask JVM???
An online frequent fullgc troubleshooting