id1 = startTimer(1000); // 开启一个1秒定时器,返回其ID id2 = startTimer(2000); id3 = startTimer(10000);
void Widget::timerEvent(QTimerEvent *event)
{
if (event->timerId() == id1) { // 判断是哪个定时器
ui->label->setText(tr("%1").arg(qrand()));
}
else if (event->timerId() == id2) {
ui->label_2->setText(tr("hello world!"));
}
else {
qApp->quit();
}
}
private slots: void timerUpdate();
#include <QTimer> #include <QDateTime>
QTimer *timer = new QTimer(this); //关联定时器溢出信号和相应的槽函数 connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate())); timer->start(1000);
void Widget::timerUpdate()
{
//获取系统现在的时间
QDateTime time = QDateTime::currentDateTime();
//设置系统时间显示格式
QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
//在标签上显示时间
ui->lineEdit->setText(str);
}
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
int rand = qrand() % 300; // 产生300以内的正整数 ui->lineEdit->move(rand, rand);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有