qfedu-basic-level/day11/qtdemo2/restaurant.cpp

26 lines
727 B
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "restaurant.h"
Restaurant::Restaurant(QWidget *parent) : QWidget(parent)
{
}
void Restaurant::receiveOrder(QString name, int n)
{
qDebug() << "店家已接收到菜单: " << name << ", 数量: " << n;
// 等待 10 秒
// QThread::msleep(10*1000); // 单位毫秒UI阻塞
// 创建定时器UI非阻塞
QTimer *timer = new QTimer();
// 绑定定时器的超时信号与 Lambda 表达式的匿名处理函数
QTimer::connect(timer,&QTimer::timeout,[&](){
qDebug() << "完成订单,上菜";
// 发送上菜的信号
emit okOrder();
});
timer->setSingleShot(true); // 单次使用
timer->start(10*1000); // 单位: 毫秒
}