当前位置:网站首页>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;
}边栏推荐
- EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
- Summary of SQL aggregate query method for yyds dry goods inventory
- RichView TRVDocParameters 页面参数设置
-
- How to prevent repeated submission of new orders
- Interesting! Database is also serverless!
- 【蓝桥杯Web】2022年第十三届蓝桥杯Web大学组国赛真题解析
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- [C language] explain the usage of memset() function in detail
- Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
猜你喜欢
![[AI server setup] CUDA environment](/img/ca/2acfc42ea3ba24934a89472a8632f6.png)
[AI server setup] CUDA environment

JS proxy

实例讲解将Graph Explorer搬上JupyterLab

A quietly rising domestic software, low-key and powerful!

Interview question 1

Arduino Stepper库驱动28BYJ-48步进电机测试程序
![P2433 [deep foundation 1-2] primary school mathematics n in one](/img/28/e5eab8927694ea002b536202a1b5ea.png)
P2433 [deep foundation 1-2] primary school mathematics n in one

Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?

Optimization of the problem that the request flow fails to terminate during page switching of easycvr cluster video Plaza

关于元宇宙下一代入口——脑机接口的实现
随机推荐
关于new Set( )还有哪些是你不知道的
Optimization of the problem that the request flow fails to terminate during page switching of easycvr cluster video Plaza
math_利用微分算近似值
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
Hls4ml entry method
DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
Win11 how to hide the taskbar? Win11 method to hide the taskbar
2022/5/23-2022/5/30
Bind this of the current scope for callback functions in other cases such as timers and delayers
RichView RichEdit SRichViewEdit PageSize 页面设置与同步
Solve the problem of slow or failed vscode download
3D panoramic model display visualization technology demonstration
Simple but modern server dashboard dashdot
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
上大学后明白了哪些坑人的事?
【多线程】锁策略
一个悄然崛起的国产软件,低调又强大!
list分割成满足和不满足条件的集合(partitioningBy)
开发那些事儿:EasyCVR平台添加播放地址鉴权功能