我应该使用 QCoreApplication::processEvents() 还是 QApplication::processEvents()? [英] Should I use QCoreApplication::processEvents() or QApplication::processEvents()?

查看:41
本文介绍了我应该使用 QCoreApplication::processEvents() 还是 QApplication::processEvents()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 QThreads 和主线程调用的方法.这种方法有时需要很长时间才能在循环中进行计算,因此我将 QCoreApplication::processEvents() 放入其中,这可以防止 GUI 冻结.在某些时候,我已经将 QCoreApplication::processEvents() 更改为 QApplication::processEvents() 但这导致 GUI 冻结(我很确定这就是它的原因,因为因为我把 QCoreApplication::processEvents() 放回去它没有再次冻结)我认为从主线程和 QThreads 调用 QApplication::processEvents() 是否正确?冻结 GUI?

I have a method which is called from both QThreads and the main thread. this method can sometimes take a long time to do its computations in a loop so I put QCoreApplication::processEvents() and this prevents the GUI from freezing. At some point I had changed QCoreApplication::processEvents() for QApplication::processEvents() but that caused the GUI to freeze (im pretty sure thats what was fereezing it because since I put QCoreApplication::processEvents() back it hasnt frozen again) Am I right to think that calling QApplication::processEvents() from both the main thread and QThreads can freeze the GUI?

推荐答案

processEvent() 都不应仅在您有实际待处理事件要处理时调用.您可能会发现这很有用:How to make Qt work when when主线程忙吗?

Neither, processEvent() should be calld only when you have actual pending events to process. You may find this useful : How to make Qt work when main thread is busy?

这篇关于我应该使用 QCoreApplication::processEvents() 还是 QApplication::processEvents()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆