我正试图在工作线程的事件循环中启动一个计时器,但是我遇到了这个错误:
QObject::startTimer: Timers can only be used with threads started with QThread
这是什么问题?
#include <QObject>
#include <QThread>
#include <QTimer>
class A : public QObject
{
Q_OBJECT
public:
A();
private:
QThread m_workerThread;
QTimer m_myTimer;
};
A::A()
{
this->moveToThread(&m_workerThread);
m_myTimer.moveToThread(&m_workerThread);
m_workerThread.start();
m_myTimer.start(1000);
}