Qt>QTimer

#include <QTimer>
#include <QTime>

class CountTimer : public QTimer
{
public:
	CountTimer() 
	{}
	~CountTimer()
	{}
	void UseTimerTenMilliSecond()
	{
		connect(_timer, SIGNAL(timeout()), this, SLOT(update()));
		_timer->start(10);
	}
	void UseTimerTenOneDay()
	{
		QTime current_time = QTime::currentTime();
		QTime next_time;
		next_time.setHMS(0, 0, 0, 0);//设定下次触发的时间,时分秒毫秒  
		int time_difference = current_time.secsTo(next_time) + 24*60*60;
		QTimer* m_timer = new QTimer(this);
		m_timer->setSingleShot(1);//定时器单次触发
		m_timer->setTimerType(Qt::PreciseTimer);//设置定时器精度为精密定时器
		connect(m_timer, SIGNAL(timeout()), this, SLOT(autoKeepSampleTimeOut()));
		m_timer->start(time_difference * 1000); //到达相应时间时,调用槽函数即可
	}
private:
	QTimer* _timer = new QTimer(this);
};
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值