#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
childThreadTimer = new QTimer(this);
parentThreadTimer = new QTimer(this);
secondmethodTimer = new QTimer(this);
connect(parentThreadTimer, &QTimer::timeout, this, &Widget::printTime);
parentThreadTimer->start(1000);
childthread = new QThread();
childthread->start();
mythread = new MyThread();
mythread->moveToThread(childthread);
connect(childThreadTimer,&QTimer::timeout, mythread, &MyThread::mySlots);
childThreadTimer->start(1000);
secondthread = new QThread();
secondthread->start();
second = new sencondmethod();
second->moveToThread(secondthread);
connect(secondmethodTimer, &QTimer::timeout,second, &sencondmethod::qDebugDateTime);
secondmethodTimer->start(1000);
}
Widget::~Widget()
{
delete ui;
}
void Widget::printTime()
{
qDebug()<<"parent thread ID:" << QThread::currentThread()<<"current time" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
}
评论0