16,216
社区成员
发帖
与我相关
我的任务
分享
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
listWidget = new QListWidget(this);
this->resize(300,300);
pBtn1= new QPushButton(this);
pBtn1->setText("stop");
thread = new QThread;
worker = new Work();
worker->moveToThread(thread);
qDebug()<<connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
qDebug()<<connect(thread, SIGNAL(started()), worker, SLOT(process()));
qDebug()<<connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
qDebug()<<connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
qDebug()<<connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
qDebug()<<connect(pBtn1,SIGNAL(clicked(bool)),worker,SLOT(finish()));
thread->start();
}
void Work::process()
{
while(1)
{
qDebug()<<"hello thread";
QCoreApplication::processEvents();
QThread::sleep(1);
}
// Widget::i =5;
// Widget::listWidget->addItem(QString("hello"));
emit finished();
emit testsig();
}
void Work::finish()
{
qDebug()<<"finish in";
emit finished();
emit testsig();
}