当前位置:网站首页>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;
}
边栏推荐
- JS proxy
- Getting started with fastdfs
- Review the collection container again
- Flask 常用组件
- PowerDesigner设计Name和Comment 替换
- List is divided into sets that meet and do not meet conditions (partitioningby)
- Keras机器翻译实战
- Image acquisition and playback of coaxpress high speed camera based on pxie interface
- math_ Use differentiation to calculate approximate value
- SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
猜你喜欢
Redis installation and startup in Windows environment (background startup)
Servlet knowledge points
STC 32位8051单片机开发实例教程 三 程序编译设置与下载
实例讲解将Graph Explorer搬上JupyterLab
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
数据分析师听起来很高大上?了解这几点你再决定是否转型
A quietly rising domestic software, low-key and powerful!
振弦采集模塊測量振弦傳感器的流程步驟
使用Zadig从0到1搭建持续交付平台
Interview questions shared in today's group
随机推荐
RichView TRVDocParameters 页面参数设置
今日群里分享的面试题
使用Zadig从0到1搭建持续交付平台
【多线程】锁策略
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
Keras机器翻译实战
C # joint Halcon application - Dahua camera acquisition class
A quietly rising domestic software, low-key and powerful!
C#聯合halcon應用——大華相機采集類
ORA-01950
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Using win7 vulnerability to crack the system login password
fastDFS入门
Modsim basic use (Modbus simulator)
再回顾集合容器
What did you learn about cheating after you went to college?
优质笔记软件综合评测和详细盘点(一) Notion、Obsidian、RemNote、FlowUs
Interesting! Database is also serverless!
internship:逐渐迈向项目开发