Files
capture/PerformanceTimer.cpp
T
2024-10-28 15:33:11 +08:00

58 lines
1.1 KiB
C++

#include "PerformanceTimer.h"
#include "mmsystem.h"
#pragma comment(lib,"winmm.lib")
#ifdef __MINGW32__
#define TIME_KILL_SYNCHRONOUS 0x0100
#endif
//高级定时器,但是结果表明没啥卵用
void CALLBACK PeriodCycle(uint timerId,uint,DWORD_PTR user,DWORD_PTR,DWORD_PTR)
{
PerformanceTimer *t=reinterpret_cast<PerformanceTimer *>(user);
emit t->timeout();
}
PerformanceTimer::PerformanceTimer(QObject *parent) : QObject(parent)
{
m_id=0;
}
PerformanceTimer::~PerformanceTimer()
{
stop();
}
void PerformanceTimer::start(int timeInterval)
{
m_interval = timeInterval;
m_id=timeSetEvent(m_interval,1,PeriodCycle,(DWORD_PTR)this,
TIME_CALLBACK_FUNCTION|TIME_PERIODIC|TIME_KILL_SYNCHRONOUS);
}
void PerformanceTimer::start()
{
m_id=timeSetEvent(m_interval,1,PeriodCycle,(DWORD_PTR)this,
TIME_CALLBACK_FUNCTION|TIME_PERIODIC|TIME_KILL_SYNCHRONOUS);
}
void PerformanceTimer::stop()
{
if(m_id)
{
timeKillEvent(m_id);
m_id=0;
}
}
void PerformanceTimer::setInterval(int interval)
{
m_interval = interval;
}