
void UiMainWindow::slotClockTimeout()
{
QString str
QDate date = QDate::currentDate()
QTime time = QTime::currentTime()
str = QString("%1-%2-%3 %4").arg(date.year()).arg(date.month()).arg(date.day()).arg(time.toString())
str = str.left(str.length() - 3)//去除秒钟的显示
ui->labelClock->setText(str)//显示时间在label上。
}
// 启动定时器QTimer *timer = new QTimer()
connect(timer, SIGNAL(timeout()), this, SLOT(timeout())
progressBar->setMaximum(100)
// 写槽函数
void MainWindow::timeout() {
static int nVal = 0
progressBar->setValue(nVal++)
}
// 再然后启动定时器即可
timer->start(1000)// 每秒触发一次
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)