widget.cpp
void Widget::on_pushButton_clicked()
{
t1->mutex.lock();
// qDebug()<<&(t1->mutex);
t1->qstr1->enqueue(“hhhhhhhhhh”);
t1->condition.wakeOne();
t1->mutex.unlock();
}
th1.cpp
QQueue *qstr1;
QWaitCondition condition;
QMutex mutex;
void Th1::run()
{
forever
{
mutex.lock();
if(qstr1->size()>0)
{
qDebug()<dequeue();
}else
{
condition.wait(&mutex);//此处的lock会释放,立即返回,但会一直wait,等待wakeone或者wakeall等信号
}
mutex.unlock();
}
}