当前位置:网站首页>Using qeventloop to realize synchronous waiting for the return of slot function
Using qeventloop to realize synchronous waiting for the return of slot function
2022-07-01 20:03:00 【Grapefruit】
Encountered a problem in doing a project , The system is externally connected with a IO equipment , The module needs to trigger reading ,
QTcpSocket The reading of is realized by slot function , The module hopes to get the result directly through only one reading interface . It needs to be done once in the interface IO, however readyRead_Slot It's not synchronous , It can't be blocked here ( Thread attempted join The way ) Wait for , Message queues that affect signals and slots , Not achieving the desired effect .
The test passed qeventloop Manually starting the message cycle can achieve this goal . Code up .
void rfidClient::getCurrentRFID(int &result)
{
if(tcpSocket == NULL)
return;
char sbuf[7] = {0};
sbuf[0] = 0xA0;
sbuf[1] = 0x04;
sbuf[2] = 0x01;
sbuf[3] = 0x89;
sbuf[4] = 0x01;
sbuf[5] = 0xD1;
sbuf[6] = '\0';
tcpSocket->write(sbuf);
QEventLoop* el = new QEventLoop();
connect(this, &rfidClient::readFinished, el, &QEventLoop::quit); //IO At the end , End the event cycle
connect(this, &rfidClient::readFinished, this, &rfidClient::analyData); //IO At the end , Processing return results
el->exec(); // Start the event cycle , wait for IO end
// here analyData Have dealt with
if(rfidResult.size() > 0)
{
result = rfidResult.at(0);
}
else
{
result = -1;
}边栏推荐
- Bind this of the current scope for callback functions in other cases such as timers and delayers
- Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
- Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
- Swiftui 4 new features complete toggle and mixed toggle multiple binding components
- 上大学后明白了哪些坑人的事?
- Getting started with fastdfs
- 开发那些事儿:EasyCVR平台添加播放地址鉴权功能
- [multithreading] lock strategy
- 关于new Set( )还有哪些是你不知道的
- 一个悄然崛起的国产软件,低调又强大!
猜你喜欢

基于图的 Affinity Propagation 聚类计算公式详解和代码示例

实战项目笔记(一)——虚拟机的创建

Solve the problem of slow or failed vscode download

【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
![[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached](/img/50/926cc5bce83f8b195b3e2072b656bf.jpg)
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached

Hls4ml entry method

STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration

开发那些事儿:EasyCVR集群设备管理页面功能展示优化
![Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding](/img/56/0c7f39406814b5bf92eca5f6670e10.jpg)
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
随机推荐
Example explanation: move graph explorer to jupyterlab
[C language] explain the usage of memset() function in detail
再回顾集合容器
PowerDesigner设计Name和Comment 替换
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
fastDFS入门
DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
关于一个神奇函数的用法
Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
实例讲解将Graph Explorer搬上JupyterLab
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)
Stack Overflow 2022 开发者调查:行业走向何方?
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
一个悄然崛起的国产软件,低调又强大!
list分割成满足和不满足条件的集合(partitioningBy)
PHP获取微信小程序和小程序商店外链地址
Error in installing sharp
Source code series of authentic children -inheritablethreadlocal (line by line source code takes you to analyze the author's ideas)