Starting QTimer In A QThread

前端 未结 6 2247
醉梦人生
醉梦人生 2020-12-01 11:05

I am trying to start a QTimer in a specific thread. However, the timer does not seem to execute and nothing is printing out. Is it something to do with the timer, the slot o

6条回答
  •  爱一瞬间的悲伤
    2020-12-01 11:50

    A QTimer only works in a thread that has an event loop.

    http://qt-project.org/doc/qt-4.8/QTimer.html

    In multithreaded applications, you can use QTimer in any thread that has an event loop. To start an event loop from a non-GUI thread, use QThread::exec(). Qt uses the timer's thread affinity to determine which thread will emit the timeout() signal. Because of this, you must start and stop the timer in its thread; it is not possible to start a timer from another thread.

提交回复
热议问题