Executing slot on every application's event loop iteration

安稳与你 提交于 2019-12-06 07:01:36

问题


How can I call my slot on every iteration of application's event loop? Only way I know is to use QTimer and on every timeout (every millisecond) signal I can call my slot. But I don't like this option, it looks like workaround.

Any suggestions how to do this more correctly?


回答1:


From the Qt 4.7 QCoreApplication::exec() documentation:

To make your application perform idle processing (i.e. executing a special function whenever there are no pending events), use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().

So your approach is what is prescribed. Look at QCoreApplication::processEvents() for more control over the event loop.




回答2:


You could also take a look at using the installEventFilter method on QCoreApplication::instance() object. This would allow you access to ALL events before they were processed for all widgets in your application.



来源:https://stackoverflow.com/questions/5124282/executing-slot-on-every-applications-event-loop-iteration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!