2

I am looking for a way to insert a call to my function or a slot with every looping of the Qt's event loop. I know there exists a solution using QTimers which is prescribed by Qt but they also say it is possible by calling processEvents(). Does that mean that I don't call exec at all and do the following?

while(true)
{
// My processing code
//  blah blah
qApp.processEvents();
}

I believe this is not what they meant. Does anyone have more idea on how to do this using the processEvents() approach?

This question is similar to Executing slot on every application's event loop iteration but I am looking for something completely without timers.

Any references or links are very much appreciated. Best,

CV

Community
  • 1
  • 1
Chenna V
  • 10,185
  • 11
  • 77
  • 104
  • You didn't say _why_ you don't want to use timers. A timer of 0 interval seems like it should be the right tool, can you explain why you don't want to use it? – rohanpm May 09 '11 at 22:30
  • The processEvents() method is to be called while Qt's event loop is running. You can use it to keep your UI responsive while you are doing a long calculation within the GUI thread. So it's not what you want, I guess... – Jonny Dee Aug 05 '11 at 21:37
  • 1
    The Qt docs say "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." So why isn't this sufficient? – Jonny Dee Aug 05 '11 at 21:47
  • 1
    If you really want complete control you could indeed use processEvents() method. Just do the loop as you wrote it but make sure it is executed with Qt's event loop. – Jonny Dee Aug 05 '11 at 21:51

0 Answers0