0
내 게임에서 경과 시간을 측정하고 표시하려면 스톱워치가 필요합니다. 이를 위해 QTime QTimer timeout() 구동 스톱워치의 CPU 사용량이 높음
나는 간단한 위젯 제작 :ZuulStopwatchWidget::ZuulStopwatchWidget(QWidget *parent) :
QWidget(parent)
{
num = new QLCDNumber(this); // create the display
num->setDigitCount(9);
time = new QTime();
time->setHMS(0,0,0,0); // set the time
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
i=0;
QString text = time->toString("hh:mm:ss");
num->display(text);
//num->setStyleSheet("* { background-color:rgb(199,147,88);color:rgb(255,255,255); padding: 7px}}");
num->setSegmentStyle(QLCDNumber::Flat); //filled flat outline
//setStyleSheet("* { background-color:rgb(236,219,187)}}");
layout = new QVBoxLayout(this);
layout->addWidget(num);
setMinimumHeight(70);
}
ZuulStopwatchWidget::~ZuulStopwatchWidget()
{
// No need to delete any object that has a parent which is properly deleted.
}
void ZuulStopwatchWidget::resetTime()
{
time->setHMS(0,0,0);
QString text = time->toString("hh:mm:ss");
num->display(text);
i=0;
stopTime();
}
void ZuulStopwatchWidget::startTime()
{
//flag=0;
timer->start(1);
}
void ZuulStopwatchWidget::stopTime()
{
timer->stop();
}
void ZuulStopwatchWidget::showTime()
{
QTime newtime;
//if(flag==1)
//i=i-1;
i=i+1;
newtime=time->addMSecs(i);
QString text = newtime.toString("mm:ss:zzz");
num->display(text);
}
을하지만 내 게임을 실행할 때 CPU 사용량은 2,5Ghz의 I5에 약 13 % 수준이다. 나는 이것이 문제는 아니지만 어리석은 시계에 대해서는 우스꽝 스럽다는 것을 알고있다.
완전히 잘못하고 있습니까? 아니면이 일반적인 관행입니까?!
미리 감사드립니다.
당신은 알고 계십니까 어쨌든 업데이트 될 때마다 밀리 초를 트리거하기 위해 타이머를 설정하는 기능에 특히 CPU 시간이 급격하게 증가하고 있습니까? 코드 등을 프로파일 링 할 수 있습니까? – chrisaycock
나는이 스톱워치 위젯이 문제를 일으킨다는 것을 확신합니다. 프로파일 링은 ml_set_interrupts_enabled (Mach 커널) 메소드가 우세하다는 것을 나타냅니다. 나는 타이머에 의해 보내지는 타임 아웃 신호라고 생각한다. 이 시계는 ms의 정밀도를 가졌지 만 여전히 1000 개의 인터럽트가 CPU 집약적이지 않습니까? (내 15 살짜리 카시오 (Casio) 시계는 배터리의 최소 용량으로 1 년간 사용할 수 있습니다.) – user558802