[Qt-qml] QML Timer triggered

1,027 views
Skip to first unread message

Pekka.E...@nokia.com

unread,
Oct 20, 2011, 5:13:58 AM10/20/11
to qt-...@qt.nokia.com

Hi,

Is the timer buggy or “works as specified”:

 

Timer {

    repeat: false

    onTriggered: {

        console.log(running) // true – I would assume false in non-repeating timer

        restart() // does not work – it calls stop and start but the timer stops this automatically

    }

}

 

The issue is clear when looking at the implementation:

 

void QDeclarativeTimer::finished()

{

    Q_D(QDeclarativeTimer);

    if (d->repeating || !d->running)

        return;

    emit triggered();

    d->running = false;

    d->firstTick = false;

    emit runningChanged();

}

 

Shouldn’t the ‘running = false’ and ‘emit triggered()’ be the other way around? This is is how the QTimer works i.e. in the timeout() handler the active property is already set to false and it can be restarted.

 

If this really is the wanted behavior, how do I restart the timer in the onTriggered event handler without setting the repeat to true (I use the same timer for many things and the repeat would just mess up everything).

 

Thanks,

-Pekka

 

michael...@nokia.com

unread,
Oct 20, 2011, 7:46:40 PM10/20/11
to Pekka.E...@nokia.com, qt-...@qt.nokia.com
Hi,
I don't think the current behavior is intentional. You can follow the issue at https://bugreports.qt.nokia.com/browse/QTBUG-22004.

Regards,
Michael

aaron....@nokia.com

unread,
Oct 20, 2011, 8:09:57 PM10/20/11
to michael...@nokia.com, Pekka.E...@nokia.com, qt-...@qt.nokia.com
Hi,

That you cannot restart the timer from within the onTriggered handler is definitely wrong.

A slightly more tricky question is, what should the running property report from within the onTriggered handler in such a case?

Cheers,

Aaron


From: qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com [qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com] on behalf of Brasser Michael (Nokia-MP-Qt/Brisbane)
Sent: Friday, October 21, 2011 9:46 AM
To: Jokela Pekka.E (Nokia-MP-Qt/Tampere)
Cc: qt-...@qt.nokia.com
Subject: Re: [Qt-qml] QML Timer triggered

Pekka.E...@nokia.com

unread,
Oct 21, 2011, 1:36:03 AM10/21/11
to aaron....@nokia.com, michael...@nokia.com, qt-...@qt.nokia.com

Thanks!

 

Ø  A slightly more tricky question is, what should the running property report from within the onTriggered handler in such a case?

 

I guess there is no “ultimate solution”. To me the QTimer solution sounds intuitive aka running is false when the timer has done its job and reported that the time has been (well) spent.

 

-P

Bo Thorsen

unread,
Oct 21, 2011, 2:13:52 AM10/21/11
to qt-...@qt.nokia.com
You need a restart flag. Otherwise, one way to look at it will fail.

Bo.

Den 21-10-2011 07:36, Pekka.E...@nokia.com skrev:
> Thanks!
>
> ØA slightly more tricky question is, what should the running property


> report from within the onTriggered handler in such a case?
>
> I guess there is no “ultimate solution”. To me the QTimer solution
> sounds intuitive aka running is false when the timer has done its job
> and reported that the time has been (well) spent.
>
> -P
>

> *From:*Kennedy Aaron (Nokia-MP-Qt/Brisbane)
> *Sent:* 21 October, 2011 03:10
> *To:* Brasser Michael (Nokia-MP-Qt/Brisbane); Jokela Pekka.E
> (Nokia-MP-Qt/Tampere)
> *Cc:* qt-...@qt.nokia.com
> *Subject:* RE: [Qt-qml] QML Timer triggered


>
> Hi,
>
> That you cannot restart the timer from within the onTriggered handler is
> definitely wrong.
>
> A slightly more tricky question is, what should the running property
> report from within the onTriggered handler in such a case?
>
> Cheers,
>
>
> Aaron
>

> ------------------------------------------------------------------------
>
> *From:*qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com
> <mailto:qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com>


> [qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com] on behalf of
> Brasser Michael (Nokia-MP-Qt/Brisbane)

> *Sent:* Friday, October 21, 2011 9:46 AM
> *To:* Jokela Pekka.E (Nokia-MP-Qt/Tampere)
> *Cc:* qt-...@qt.nokia.com <mailto:qt-...@qt.nokia.com>
> *Subject:* Re: [Qt-qml] QML Timer triggered


>
> Hi,
>
> On 20/10/2011, at 7:13 PM, ext Pekka.E...@nokia.com

> <mailto:Pekka.E...@nokia.com> wrote:
>
> Is the timer buggy or “works as specified”:
>
> Timer {
>
> repeat: false
>
> onTriggered: {
>
> console.log(running) // true – I would assume false in non-repeating
> timer
>
> restart() // does not work – it calls stop and start but the timer
> stops this automatically
>
> }
>
> }
>
> The issue is clear when looking at the implementation:
>
> voidQDeclarativeTimer::finished()
>
> {
>
> Q_D(QDeclarativeTimer);
>

> if(d->repeating||!d->running)


>
> return;
>
> emit triggered();
>
> d->running = false;
>
> d->firstTick=false;
>
> emitrunningChanged();
>
> }
>
> Shouldn’t the ‘running = false’ and ‘emit triggered()’ be the other
> way around? This is is how the QTimer works i.e. in

> thetimeout()handler theactiveproperty is already set to false and it


> can be restarted.
>
> If this really is the wanted behavior, how do I restart the timer in
> the onTriggered event handler without setting the repeat to true (I
> use the same timer for many things and the repeat would just mess up
> everything).
>
> I don't think the current behavior is intentional. You can follow the
> issue at https://bugreports.qt.nokia.com/browse/QTBUG-22004.
>
> Regards,
>
> Michael
>
>
>

> _______________________________________________
> Qt-qml mailing list
> Qt-...@qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml


Bo Thorsen,
Fionia Software.

--

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

jan-arve...@nokia.com

unread,
Oct 21, 2011, 3:45:58 AM10/21/11
to aaron....@nokia.com, michael...@nokia.com, Pekka.E...@nokia.com, qt-...@qt.nokia.com

Why would you ask for the running property from within onTriggered anyway?

 

Jan-Arve

Bo Thorsen

unread,
Oct 21, 2011, 4:03:59 AM10/21/11
to qt-...@qt.nokia.com
Den 21-10-2011 09:45, jan-arve...@nokia.com skrev:
> Why would you ask for the running property from within onTriggered anyway?

{
onTriggered(): doSomething()
onSomethingElse(): doSomething()
}

In doSomething(), the check happens.

This is just one example, I can come up with more if you want to.

But this actually reminds me of the old "un-ask the question". It's the
wrong question, since calls like isRunning just always have to work.

Bo.

> *From:*qt-qml-bounces+jan-arve.saether=noki...@qt.nokia.com
> [mailto:qt-qml-bounces+jan-arve.saether=noki...@qt.nokia.com] *On
> Behalf Of *Kennedy Aaron (Nokia-MP-Qt/Brisbane)
> *Sent:* 21. oktober 2011 02:10
> *To:* Brasser Michael (Nokia-MP-Qt/Brisbane); Jokela Pekka.E
> (Nokia-MP-Qt/Tampere)
> *Cc:* qt-...@qt.nokia.com
> *Subject:* Re: [Qt-qml] QML Timer triggered


>
> Hi,
>
> That you cannot restart the timer from within the onTriggered handler is
> definitely wrong.
>
> A slightly more tricky question is, what should the running property
> report from within the onTriggered handler in such a case?
>
> Cheers,
>
>
> Aaron
>

> ------------------------------------------------------------------------
>
> *From:*qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com


> [qt-qml-bounces+aaron.kennedy=noki...@qt.nokia.com] on behalf of
> Brasser Michael (Nokia-MP-Qt/Brisbane)

> *Sent:* Friday, October 21, 2011 9:46 AM
> *To:* Jokela Pekka.E (Nokia-MP-Qt/Tampere)
> *Cc:* qt-...@qt.nokia.com

> *Subject:* Re: [Qt-qml] QML Timer triggered


>
> Hi,
>
> On 20/10/2011, at 7:13 PM, ext Pekka.E...@nokia.com

> <mailto:Pekka.E...@nokia.com>wrote:


>
> Is the timer buggy or “works as specified”:
>
> Timer {
>
> repeat: false
>
> onTriggered: {
>
> console.log(running) // true – I would assume false in non-repeating
> timer
>
> restart() // does not work – it calls stop and start but the timer
> stops this automatically
>
> }
>
> }
>
> The issue is clear when looking at the implementation:
>
> voidQDeclarativeTimer::finished()
>
> {
>
> Q_D(QDeclarativeTimer);
>

> if(d->repeating||!d->running)


>
> return;
>
> emit triggered();
>
> d->running = false;
>
> d->firstTick=false;
>
> emitrunningChanged();
>
> }
>
> Shouldn’t the ‘running = false’ and ‘emit triggered()’ be the other
> way around? This is is how the QTimer works i.e. in

> thetimeout()handler theactiveproperty is already set to false and it


> can be restarted.
>
> If this really is the wanted behavior, how do I restart the timer in
> the onTriggered event handler without setting the repeat to true (I
> use the same timer for many things and the repeat would just mess up
> everything).
>
> I don't think the current behavior is intentional. You can follow the
> issue at https://bugreports.qt.nokia.com/browse/QTBUG-22004.
>
> Regards,
>
> Michael
>
>
>

Pekka.E...@nokia.com

unread,
Oct 21, 2011, 6:36:01 AM10/21/11
to b...@fioniasoftware.dk, qt-...@qt.nokia.com
Thanks Bo! This was exactly my scenario.

{
onTriggered(): doSomething()
onSomethingElse(): doSomething()
}

Bo.

> console.log(running) // true - I would assume false in non-repeating
> timer
>
> restart() // does not work - it calls stop and start but the timer

mikko.k...@nokia.com

unread,
Nov 30, 2011, 6:47:42 AM11/30/11
to Pekka.E...@nokia.com, b...@fioniasoftware.dk, qt-...@qt.nokia.com
Hi,
I just happened to fight with the same thing.
My solution was to have two similar timers with the same trigger handler.
I just then restarted the other timer in the handler not the same one.

- Mikko
________________________________________
From: qt-qml-bounces+mikko.kiilholma=noki...@qt.nokia.com [qt-qml-bounces+mikko.kiilholma=noki...@qt.nokia.com] on behalf of ext Pekka.E...@nokia.com [Pekka.E...@nokia.com]
Sent: Friday, October 21, 2011 12:36 PM
To: b...@fioniasoftware.dk; qt-...@qt.nokia.com

Reply all
Reply to author
Forward
0 new messages