在 Qlabel 中使用 QTime 和 Qtimer 作为时钟会导致大量 cpu 使用

using QTime and Qtimer as clock in Qlabel lead to heavy cpu usage

我在激活 QTimer To Show A clock inside a Qlabel 时遇到问题,我的小软件将使用大约 25% 到 40% 的 CPU 功率 (I3 4160) 所以如何解决占用更少的硬件资源?

QTimer *timer1 = new QTimer(this);
     connect(timer1,SIGNAL(timeout()),this,SLOT(showtime()));
     timer1->start();

这是我的 showtime() 函数

void Findlistrecord::showtime(){
    QTime time = QTime::currentTime();
    QString time_totext = time.toString("hh : mm : ss");
    ui->timelabel->setText(time_totext);
}

据我所知,您没有为计时器设置时间间隔,因此您的计时器会尽快触发。如果你想以秒的精度显示时间,我建议使用 1000ms 的间隔来减少进程开销。

timer1->start(1000);