在线程中调用定时器
嗨,大家好,我们都知道无论线程和定时器,这两个单独使用都非常简单,Qt帮助文档有很详细的Demo。但是在线程中使用定时器就稍微有点麻烦了,一不注意就容易掉坑里。
首先理解connect的第五个参数很重要—连接类型
1、connect的第五个参数介绍
Qt::AutoConnection
(Default) If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.
Qt::DirectConnection
The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread.
Qt::QueuedConnection
The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread.
Qt::BlockingQueuedConnection
Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock.
Qt::UniqueConnecti