嗨,我有一个具有运行功能的类QTimer
(例如每 30 毫秒运行一次)
class testclass
{
public slots:
void DoSomthing();
}
testclass::testclass()
{
QTimer *timer = new QTimer();
connect(timer , SIGNAL(timeout()) , this , SLOT(DoSomthing());
timer->start(30);
}
但我希望我的DoSomthing()
函数在单独的线程中运行,这意味着DoSomthing()
在单独的线程中创建函数并使用计时器控制函数(每隔一段时间在线程中运行我的函数)。
class testclass
{
public slots:
void DoSomthing();
}
testclass::testclass()
{
QThread thread = new QThread ();
connect(thread , SIGNAL(started()) , this , SLOT(DoSomthing());
QTimer *timer = new QTimer();
connect(???, SIGNAL(?????) , ????, SLOT(?????); // how i can continue this code
timer->start(30);
}
我该怎么做?