当前位置:网站首页>QT event cycle
QT event cycle
2022-06-30 08:05:00 【Flying】
1. In general, our event cycle is made up of exec() To open it , Take the following example :
QCoreApplicaton::exec()
QApplication::exec()
QDialog::exec()
QThread::exec()
QDrag::exec()
QMenu::exec()
These all start the event cycle , The event loop is first an infinite “ loop ”, The program is in exec() There's an infinite loop inside , Can make you follow exec() The following code won't get a chance to run , Until the program starts from exec() Jump out of . from exec() When jumping out , The event loop is terminated .QEventLoop::quit() Can terminate the event loop .
An event loop is actually similar to an event queue , Handle the listed events in turn , When the time is finished and the time cycle is not over , It's actually more like an unoccupied CPU The event for(;;) loop .
Its essence is actually to redistribute time slices in the form of queues .
2. Event loops can be nested , When in a sub event loop , The events in the parent event loop are actually in an interrupted state , When the sub loop jumps out exec Then the events in the parent loop can be executed .
Of course , This does not mean that when executing a sub loop , Similarly, the interface response in the parent loop will be interrupted , Because often there will be most of the events of the parent loop in the child loop , perform QMessageBox::exec(),QEventLoop::exec() When , Although these exec() Interrupted main() Medium QApplication::exec(), But because of GUI The response of the interface has been included in the sub loop , therefore GUI The interface is still responsive .
3. If a sub event loop is still valid , But its parent loop is forced to jump out , At this point, the parent loop does not immediately execute the jump out , Instead, wait for the sub event loop to jump out , The parent loop will jump out
Take a few examples , For example, if you want to wait for the main thread 100ms, Never use sleep Well , That would lead to GUI When the interface stops responding , But you can avoid this with event loops :
QEventLoop loop;
QTimer::singleShot(100, &loop, SLOT(quit()));
loop.exec();
also , For example, for a slot function , After triggering, a... Will pop up dialog, But if you write like this , The window will flash by :
void ****::mySLot{
QDialog dlg;
dlg.show();
}
Of course, you can use here will dlg Change to a static member , To solve this problem by prolonging the life span , But it can also be used here eventLoop To solve this problem :
void ****::mySLot{
QDialog dlg;
dlg.show();
QEventLoop loop;
connect(&dlg, SIGNAL(finished(int)), &loop, SLOT(quit()));
loop.exec(QEventLoop::ExcludeUserInputEvents);
}
边栏推荐
- MySQL加索引语句不加锁:ALGORITHM=INPLACE, LOCK=NONE
- Implementation of remote monitoring by camera in Experiment 5
- vulfocus入门靶机
- Pycharm Dlib library installation
- Vulfocus entry target
- July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)
- 鲸探NFT数字臧品系统开发技术分享
- December 4, 2021 [metagenome] - sorting out the progress of metagenome process construction
- 【NVMe2.0b 14-6】Format NVM、Keep Alive、Lockdown command
- F12 packet capture is used for the whole process analysis of postman interface test
猜你喜欢

回文子串、回文子序列

Cesium learning notes (III) creating instances

Environment configuration of ROS Aubo manipulator

More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!

Construction of energy conservation supervision system for campus buildings of ankery University

你了解IP协议吗?
![[tensorflow GPU] building of deep learning environment under windows11](/img/10/6d30d4c310e6677049a1012d47f773.png)
[tensorflow GPU] building of deep learning environment under windows11

多快好省,低门槛AI部署工具FastDeploy测试版来了!

领域驱动下cloud项目中单个服务的示例

直击产业落地 | 飞桨重磅推出业界首个模型选型工具
随机推荐
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)
期末複習-PHP學習筆記5-PHP數組
Cadence physical library lef file syntax learning [continuous update]
Introduction to opencv (I): image reading and display
牛客小白月赛52
HelloWorld
tp5设置直接下载文件
JS code case
深度学习——Bounding Box预测
Simple application of generating function -- integer splitting 2
[flower carving experience] 13 build the platformio ide development environment of esp32c3
Cesium learning notes (I)
深度学习——GRU单元
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
Pycharm Dlib library installation
牛客小白月賽52
Want to change careers, but don't know what to do? This article is written for you who are confused
回文子串、回文子序列
【Tensorflow-gpu】window11下深度学习环境搭建
深度学习——网络中的网络以及1x1卷积