QTime Class Reference


The QTime class provides time functions 24 hours a day. (details) (complete member list)

#include <qdatetm.h>

Public Members

Static Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

The QTime class provides time functions 24 hours a day.

The time resolution of QTime is a millisecond, although the accuracy depends on the underlying operating system. Some operating systems (e.g. Linux) support a one-millisecond resolution, while others (i.e. MS-DOS and Windows) support only a 55 millisecond resolution.


Member Function Documentation

QTime::QTime ()

Constructs a null time 00:00:00.000. Null times are valid.

QTime::QTime (int h, int m, int s=0, int ms=0)

Constructs a time with hour h, minute m, seconds s and milliseconds ms.

QTime QTime::addMSecs (long ms) const

Returns the time plus ms milliseconds.

QTime QTime::addSecs (long nsecs) const

Returns the time plus nsecs seconds.

QTime QTime::currentTime ()

Returns the current time.

long QTime::elapsed ()

Returns the number of microseconds that have elapsed since start() or restart() were called.

int QTime::hour () const

Returns the hour part (0..23) of the time.

bool QTime::isValid () const

Returns TRUE if the time is valid, or FALSE if the time is invalid or null. The time 23:30:55.746 is valid, while 24:12:30 is invalid.

bool QTime::isValid (int h, int m, int s, int ms=0)

Returns TRUE if the specified time is valid.

int QTime::minute () const

Returns the minute part (0..59) of the time.

int QTime::msec () const

Returns the millisecond part (0..999) of the time.

long QTime::msecsTo (const QTime &t) const

Returns the number of milliseconds between this time and t.

long QTime::restart ()

Restarts for timing, and returns the number of microseconds that have elapsed since start() or restart().

See also: start(), elapsed().

int QTime::second () const

Returns the second part (0..59) of the time.

long QTime::secsTo (const QTime &t) const

Returns the number of seconds between this time and t.

bool QTime::setHMS (int h, int m, int s, int ms=0)

Sets the hour h, minute m, seconds s and milliseconds ms. Returns TRUE if the time is valid, FALSE if it is invalid.

void QTime::start ()

Sets the time to the current time, e.g. for timing:

  QTime t;
  t.start();                            // start clock
  ... // some lengthy task
  printf( "%d\n", t.elapsed() );        // prints # msecs elapsed

See also: restart(), elapsed().

QString QTime::toString () const

Converts the date to a string, which is returned. Milliseconds are not included. The string format is "03:40:13".


Related Functions

QDataStream & operator<< (QDataStream &s, const QTime &t)

Writes the time t to the stream s and returns a reference to s.

QDataStream & operator>> (QDataStream &s, QTime &t)

Reads the time t from the stream s and returns a reference to s.


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

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech