QTimer Class Reference


The QTimer class provides timer signals and single-shot timers. More...

#include <qtimer.h>

Inherits QObject.

List of all member functions.

Public Members

Signals

Static Public Members

Protected Members


Detailed Description

The QTimer class provides timer signals and single-shot timers.

It uses timer events internally to provide a more versatile timer. QTimer is very easy to use, create a QTimer, call start() to start it and connect its timeout() to the appropriate slots, then when the time is up it will emit timeout().

Note that a QTimer object is destroyed automatically when its parent object is destroyed.

Example:

    QTimer *timer = new QTimer( myObject );
    timer->start( 2000, TRUE );                 // 2 seconds single-shot
    connect( timer, SIGNAL(timeout()),
             myObject, SLOT(timerDone()) );

An alternative is to call QObject::startTimer() for your object and reimplement the QObject::timerEvent() event handler in your class (it must inherit QObject). The advantage is that you can have multiple running timers, each having a unique identifier. The disadvantage is that it does not support such high-level features as single-shot timers or signals.

Examples: aclock/aclock.cpp


Member Function Documentation

QTimer::QTimer ( QObject *parent=0, const char *name=0)

Constructs a timer with a parent and a name.

Notice that the destructor of the parent object will destroy this timer object.

QTimer::~QTimer ()

Destroys the timer.

void QTimer::changeInterval ( int msec)

Changes the timeout interval to msec milliseconds.

If the timer signal is pending, it will be stopped and restarted, otherwise it will be started.

See also: start() and isActive().

bool QTimer::event ( QEvent *e) [virtual protected]

Handles timer events. Emits timeout() when a timer event is received.

Reimplemented from QObject.

bool QTimer::isActive () const

Returns TRUE if the timer is running (pending), or FALSE is the timer is idle.

void QTimer::singleShot ( int msec, QObject *receiver, const char *member) [static]

This static function calls a slot after a given time interval.

It is very convenient to use this function because you do not need to bother with a timerEvent or to create a local QTimer object.

Example:

      #include <qapp.h>
      #include <qtimer.h>

      int main( int argc, char **argv )
      {
          QApplication a( argc, argv );
          QTimer::singleShot( 10*60*1000, &a, SLOT(quit()) );
           ... // create your widgets
          return a.exec();
      }

This sample program automatically terminates after 10 minutes (i.e. 600000 milliseconds).

int QTimer::start ( int msec, bool sshot = FALSE)

Starts the timer with a msecs milliseconds timeout.

If sshot is TRUE, the timer will be activated only once, otherwise it will continue until it is stopped.

Any pending timer will be stopped.

See also: stop(), changeInterval() and isActive().

Examples: aclock/aclock.cpp

void QTimer::stop ()

Stops the timer.

See also: start().

void QTimer::timeout () [signal]

This signal is emitted when the timer is activated.


This file is part of the Qt toolkit, copyright © 1995-96 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:51, 1996/09/24 for Qt version 1.0 by the webmaster at Troll Tech