Logo Search packages:      
Sourcecode: qt4-x11 version File versions

int QObject::startTimer ( int  interval  )  [inherited]

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.

The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.

If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.

Example:

        class MyObject : public QObject
        {
            Q_OBJECT

        public:
            MyObject(QObject *parent = 0);

        protected:
            void timerEvent(QTimerEvent *event);
        };

        MyObject::MyObject(QObject *parent)
            : QObject(parent)
        {
            startTimer(50);     // 50-millisecond timer
            startTimer(1000);   // 1-second timer
            startTimer(60000);  // 1-minute timer
        }

        void MyObject::timerEvent(QTimerEvent *event)
        {
            qDebug() << "Timer ID:" << event->timerId();
        }

Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.

The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.

See also:
timerEvent(), killTimer(), QTimer::singleShot()

Reimplemented in QTimer.

Definition at line 1450 of file qobject.cpp.

Referenced by Q3DateEdit::addNumber(), Q3TimeEdit::addNumber(), QTreeView::columnResized(), QTableView::columnResized(), QClipboard::event(), QLineEdit::event(), QWindowsStyle::eventFilter(), QMotifStyle::eventFilter(), QPlastiqueStyle::eventFilter(), QLineEdit::focusInEvent(), QClipboard::mimeData(), QTableView::rowResized(), QTimeLine::setPaused(), QTimeLine::start(), QBasicTimer::start(), QTimer::start(), and QAbstractSpinBox::timerEvent().

{
    Q_D(QObject);

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

    d->pendTimer = true;                                // set timer flag

    if (!d->threadData->eventDispatcher) {
        qWarning("QObject::startTimer: QTimer can only be used with threads started with QThread");
        return 0;
    }
    return d->threadData->eventDispatcher->registerTimer(interval, this);
}


Generated by  Doxygen 1.6.0   Back to index