3

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?

asmodan
  • 85
  • 1
  • 6
  • 1
    Your QTimer can have a timeout of 0, which will run once per event loop instead of once per millisecond, which will only *probably* run once per event loop. :-) Still a bit of a workaround, though. – Daniel Gallagher Feb 26 '11 at 00:53
  • Yes, I know this and I am using it now, but it is not what I want. – asmodan Feb 26 '11 at 11:22

2 Answers2

3

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
0

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.

jsherer
  • 910
  • 6
  • 8