Qt World Summit: Register Today!

Qtimer: Fireing multiple threads concurrently

  • I'm using a QTimer to initiate a series of FFTs. It's my understanding that Qtimer essentially creates a new thread each time its interval times out. However, it's not doing so until the current FFT expires. For example, if the timer's set to go off every half second, but the FFT takes one second, the timer only fires every second. If the timer's set to fire every 2 seconds, it fires every 2 seconds.

    Am I misunderstanding Qtimer?

  • Yes, you have misunderstand it.

    Timer never create new thread for you. If you want to the slot called in sub-thread, you must create QThread yourself.

    Timers will never time out earlier than the specified timeout value and they are not guaranteed to time out at the exact value specified.

  • QTimer has nothing to do with threads. Nothing at all. QTimer events don't create threads, and threads should not be used instead of/for timers.

    QTimer needs the eventloop of the thread it lives in to be running for it to work. If your thread is occupied calculating a FFT, the timer will not fire at the expected moment. Timers do not break or interrupt the normal flow of code.

  • Thanks! Question answered.

Log in to reply