1

I'm preparing to add an idle timer to a shared KDE library (kwallet). While I presume it will mostly be called from a thread that already has an event loop, I cannot be sure of that. Is there a a way to check for this?

Alternatively, being rather new to Qt development, what would be the leanest way to spawn that timer in its own thread so that it will definitely have an event loop?

RJVB
  • 698
  • 8
  • 18
  • Doesnt QThread::isRunning do that? You can get the current thread with QThread::currentThread... – Thomas Sep 08 '14 at 10:36
  • The documentation isn't clear - just from the name I'd guess it would return true for the current thread ... – RJVB Sep 08 '14 at 12:38
  • According to [this](http://stackoverflow.com/a/17094375/3967585), isRunning refers to the state of the thread rather than to wether the thread is the current thread. However, i agree the doc is not that clear and it seems that the eventloop is only equal to isRunning() if QThread::run calls exec(), which you might not know. – Thomas Sep 08 '14 at 13:04
  • Alternative found [here](http://stackoverflow.com/a/10493492/3967585) – Thomas Sep 08 '14 at 13:17
  • using moveToThread you mean? Yeah, that might be of use if it turns out I need to spin my own thread. – RJVB Sep 08 '14 at 17:32
  • Yeah i meant that, since you asked for an easy way to spawn a thread for your timer. – Thomas Sep 08 '14 at 18:28

0 Answers0