HttpNetworkCheck::HttpNetworkCheck(QObject *parent) : QObject(parent)
{
QThread *thread = new QThread;
this->moveToThread(thread);
m_timer = new QTimer;
m_timer->moveToThread(thread); //在线程中,定时器也需要移到对应的线程,否则定时器不生效.
connect(m_timer,SIGNAL(timeout()),this,SLOT(slottimer()), Qt::DirectConnection);
connect(thread, SIGNAL(started()), this, SLOT(slotstart())); // 启动函数需要有线程来启动才在线程中运行,直接调用会在进程中运行。
thread->start();
}
void HttpNetworkCheck::slotstart()
{
m_timer->start(1000);
}
12-23
439
01-16
1321
01-19
572