문제

I am trying to use QTimer and I is starting well, but When I am trying to stop it by checking its state using isActive, it returning false always but the code inside the slot for timer is executing in correct interval.

here is code

void CurrentController::currentAction(void)
{
    count++;
    QTimer *timer = new QTimer(this);
    if(count == 1)
    {
        qDebug()<< "Count" << count;

        QObject::connect(timer, SIGNAL(timeout()), this, SLOT(callMethod()));
        timer->setInterval(10000);
        timer->start();
    }

for stopping timer

    if(count >= 2)
    {
        qDebug()<< "Count2" <<timer->isActive();
        timer->stop();
        count = 0;
    }
}

Help appreciated thanks...

도움이 되었습니까?

해결책

This is a local variable, not d->timer:

QTimer *timer = new QTimer(this); 

Yet, here you're checking if some d->timer is active:

qDebug()<< "Count2" << d->timer->isActive();

And a line later you refer to timer, not d->timer again:

timer->stop();

Maybe you need to decide which timer you wish to use, and stick with it :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top