qt4的QTimer怎么用列举一下c++代码
下面是一个使用Qt4的QTimer的简单示例代码:
#include <QApplication>
#include <QTimer>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTimer timer;
timer.setInterval(1000); // 设置定时器间隔为1秒
QObject::connect(&timer, &QTimer::timeout, [&](){
qDebug() << "Timer triggered!";
});
timer.start(); // 启动定时器
return a.exec();
}
以上代码创建了一个定时器,每隔1秒触发一次timeout信号,回调函数中打印一条信息。最后启动应用程序事件循环。
原文地址: https://www.cveoy.top/t/topic/bRt6 著作权归作者所有。请勿转载和采集!