PDA

View Full Version : QTimer QBasicTimer and QObject::startTimer



SABROG
15th June 2009, 16:40
QObject::startTimer(), what this QTimer or QBasicTimer? Why "Wyggly" example use QBasicTimer instead QObject::startTimer()?

jpn
15th June 2009, 17:21
QBasicTimer is light-weight; there's no signals and slots involved like in QTimer. QBasicTimer is still a bit more convenient to use than startTimer().

SABROG
15th June 2009, 17:24
QBasicTimer is light-weight; there's no signals and slots involved like in QTimer. QBasicTimer is still a bit more convenient to use than startTimer().

This writing in docs, but i don't find where QObject::startTimer use QTimer and startTimer also use timerEvent, not signals.

jpn
15th June 2009, 17:28
This writing in docs, but i don't find where QObject::startTimer use QTimer and startTimer also use timerEvent, not signals.
QObject::startTimer() doesn't use QTimer, but vice versa. QTimer uses QObject::startTimer() and informs timouts via signals. That's exactly what makes QTimer high-level and easy to use, but heavier than startTimer() or QBasicTimer.

SABROG
15th June 2009, 17:43
QObject::startTimer() don't use QTimer or QBasicTimer:

startTimer()->eventDispatcher->SetTimer() (winapi)

so QObject::startTimer more lightweight than QTimer or QBasicTimer and i don't understand why QBasicTimer used in "Wyggly" example. May be this just don't good example.

jpn
15th June 2009, 17:55
QObject::startTimer() don't use QTimer or QBasicTimer:
Isn't that what I just said?



startTimer()->eventDispatcher->SetTimer() (winapi)

so QObject::startTimer more lightweight than QTimer or QBasicTimer and i don't understand why QBasicTimer used in "Wyggly" example. May be this just don't good example.


QObject::startTimer() is the lowest-level timer available in Qt.
QBasicTimer brings more convenience, but it's basically the same than using QObject::startTimer() but more convenient.
QTimer is a high-level timer class. Very easy and convenient to use. Hides the timer events from the application developer. Just create a timer object, connect signals and slots, start the timer and you're done.
The Wyggle example was chosen to demonstrate the usage of QBasicTimer. Isn't it nice that there is at least some example using QBasicTimer? Most of them use QTimer instead, just like recommended by QBasicTimer docs.

SABROG
15th June 2009, 18:17
Isn't that what I just said?

Yes, i see your post after my reply. But this very strange:



int QObject::startTimer(int interval)
{
Q_D(QObject);
...
if (interval < 0) {
qWarning("QObject::startTimer: QTimer cannot have a negative interval");
return 0;
}


Don't used, but talking about QTimer.

jpn
15th June 2009, 18:37
Don't used, but talking about QTimer.
Well, I admit that the comment looks peculiar at first sight, but it really makes sense because QObject::startTimer() is rarely used directly, but mostly via QTimer. Besides, this way the warning is fully understandable to both QObject::startTimer() and QTimer users, isn't it?