Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QTime Class Reference

The QTime class provides clock time functions. More...

#include </home/clem/local/src/opie/qmake/include/qdatetime.h>

List of all members.

Public Member Functions

 QTime ()
 QTime (int h, int m, int s=0, int ms=0)
bool isNull () const
bool isValid () const
int hour () const
int minute () const
int second () const
int msec () const
QString toString (Qt::DateFormat f=Qt::TextDate) const
QString toString (const QString &format) const
bool setHMS (int h, int m, int s, int ms=0)
QTime addSecs (int secs) const
int secsTo (const QTime &) const
QTime addMSecs (int ms) const
int msecsTo (const QTime &) const
bool operator== (const QTime &d) const
bool operator!= (const QTime &d) const
bool operator< (const QTime &d) const
bool operator<= (const QTime &d) const
bool operator> (const QTime &d) const
bool operator>= (const QTime &d) const
void start ()
int restart ()
int elapsed () const

Static Public Member Functions

static QTime currentTime ()
static QTime currentTime (Qt::TimeSpec)
static QTime fromString (const QString &s, Qt::DateFormat f=Qt::TextDate)
static bool isValid (int h, int m, int s, int ms=0)

Static Private Member Functions

static bool currentTime (QTime *)
static bool currentTime (QTime *, Qt::TimeSpec)

Private Attributes

uint ds

Friends

class QDateTime
Q_EXPORT QDataStreamoperator<< (QDataStream &, const QTime &)
Q_EXPORT QDataStreamoperator>> (QDataStream &, QTime &)


Detailed Description

The QTime class provides clock time functions.

A QTime object contains a clock time, i.e. the number of hours, minutes, seconds, and milliseconds since midnight. It can read the current time from the system clock and measure a span of elapsed time. It provides functions for comparing times and for manipulating a time by adding a number of (milli)seconds.

QTime uses the 24-hour clock format; it has no concept of AM/PM. It operates in local time; it knows nothing about time zones or daylight savings time.

A QTime object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly, or by using the static function currentTime(), which creates a QTime object that contains the system's clock time. Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

The hour(), minute(), second(), and msec() functions provide access to the number of hours, minutes, seconds, and milliseconds of the time. The same information is provided in textual format by the toString() function.

QTime provides a full set of operators to compare two QTime objects. One time is considered smaller than another if it is earlier than the other.

The time a given number of seconds or milliseconds later than a given time can be found using the addSecs() or addMSecs() functions. Correspondingly, the number of (milli)seconds between two times can be found using the secsTo() or msecsTo() functions.

QTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.

See also:
QDate, QDateTime

Definition at line 123 of file qdatetime.h.


Constructor & Destructor Documentation

QTime::QTime  )  [inline]
 

Constructs the time 0 hours, minutes, seconds and milliseconds, i.e. 00:00:00.000 (midnight). This is a valid time.

See also:
isValid()

Definition at line 126 of file qdatetime.h.

Referenced by fromString().

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.

h must be in the range 0..23, m and s must be in the range 0..59, and ms must be in the range 0..999.

See also:
isValid()

Definition at line 1264 of file qdatetime.cpp.

References setHMS().


Member Function Documentation

QTime QTime::addMSecs int  ms  )  const
 

Returns a QTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).

Note that the time will wrap if it passes midnight. See addSecs() for an example.

See also:
addSecs(), msecsTo()

Definition at line 1505 of file qdatetime.cpp.

References ds, MSECS_PER_DAY, and t.

Referenced by addSecs(), and LoopControl::setPosition().

QTime QTime::addSecs int  nsecs  )  const
 

Returns a QTime object containing a time nsecs seconds later than the time of this object (or earlier if nsecs is negative).

Note that the time will wrap if it passes midnight.

Example:

    QTime n( 14, 0, 0 );                // n == 14:00:00
    QTime t;
    t = n.addSecs( 70 );                // t == 14:01:10
    t = n.addSecs( -70 );               // t == 13:58:50
    t = n.addSecs( 10*60*60 + 5 );      // t == 00:00:05
    t = n.addSecs( -15*60*60 );         // t == 23:00:00

See also:
addMSecs(), secsTo(), QDateTime::addSecs()

Definition at line 1475 of file qdatetime.cpp.

References addMSecs().

Referenced by IRCMessageParser::parseNumericalWhoisIdle(), DateEntry::startTimeChanged(), and TempScreenSaverMonitor::timerEvent().

bool QTime::currentTime QTime ct,
Qt::TimeSpec  ts
[static, private]
 

For internal use only.

Fetches the current time, for the TimeSpec ts, and returns TRUE if the time is within one minute after midnight, otherwise FALSE. The return value is used by QDateTime::currentDateTime() to ensure that the date there is correct. The default TimeSpec is LocalTime.

See also:
Qt::TimeSpec

Definition at line 1654 of file qdatetime.cpp.

References ds, FALSE, Qt::LocalTime, MSECS_PER_HOUR, MSECS_PER_MIN, qWarning(), and t.

bool QTime::currentTime QTime ct  )  [static, private]
 

For internal use only.

Fetches the current time and returns TRUE if the time is within one minute after midnight, otherwise FALSE. The return value is used by QDateTime::currentDateTime() to ensure that the date there is correct.

Definition at line 1638 of file qdatetime.cpp.

References currentTime(), and Qt::LocalTime.

QTime QTime::currentTime Qt::TimeSpec  ts  )  [static]
 

Returns the current time as reported by the system clock, for the TimeSpec ts. The default TimeSpec is LocalTime.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

See also:
Qt::TimeSpec

Definition at line 1598 of file qdatetime.cpp.

References currentTime(), and t.

QTime QTime::currentTime  )  [static]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the current time as reported by the system clock.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

Definition at line 1584 of file qdatetime.cpp.

References Qt::LocalTime.

Referenced by StylusNormalizer::addEvent(), IRCTab::appendTimestamp(), Clock::Clock(), QDateTime::currentDateTime(), currentTime(), DateBookDay::DateBookDay(), DateBookDay::dateChanged(), MScanListItem::decorateItem(), Dice::Dice(), EffectiveEvent::EffectiveEvent(), elapsed(), KateCommands::InsertTime::execCmd(), DatebookPluginWidget::getDates(), MLogWindow::log(), Man::Man(), BackGammon::mouse(), Target::newTarget(), OEffectiveEvent::OEffectiveEvent(), DateBookDayWidget::paintEvent(), QTetrix::QTetrix(), MScanListItem::receivedBeacon(), Referee::Referee(), DateBookDay::relayoutPage(), restart(), TimeTabWidget::saveSettings(), Man::setInitialCoords(), DateBookDay::setStartViewTime(), StylusNormalizer::slotAveragePoint(), TimeTabWidget::slotTZChanged(), start(), Man::start(), Wellenreiter::startClicked(), TicTacGameBoard::TicTacGameBoard(), CityTime::timerEvent(), LauncherClock::timerEvent(), MiscFunctions::uniqueString(), Clock::updateClock(), and DateBookDay::updateView().

int QTime::elapsed  )  const
 

Returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

Note that the counter wraps to zero 24 hours after the last call to start() or restart.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

Warning:
If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.
See also:
start(), restart()

Definition at line 1798 of file qdatetime.cpp.

References currentTime(), and msecsTo().

Referenced by DateBook::DateBook(), TestItem::end(), ODateBookAccessBackend_SQL::extractUids(), OContactAccessBackend_SQL::extractUids(), OContactAccessBackend_SQL::find(), Opie::OPimContactAccessBackend_SQL::find(), BenchmarkInfo::gfxRendering(), OThemePixmap::isOld(), ZCameraIO::isShutterPressed(), StartingAppList::isStarting(), main(), OContactAccessBackend_SQL::OContactAccessBackend_SQL(), Opie::OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL(), ZCameraIO::read(), Opie::ODateBookAccessBackend_SQL::requestCustom(), OContactAccessBackend_SQL::requestCustom(), Opie::OPimContactAccessBackend_SQL::requestCustom(), OContactAccessBackend_SQL::requestNonCustom(), Opie::OPimContactAccessBackend_SQL::requestNonCustom(), Clock::resetStopWatch(), BenchmarkInfo::run(), OContactAccessBackend_SQL::sorted(), Opie::OPimContactAccessBackend_SQL::sorted(), Converter::start_conversion(), LoopControl::startAudio(), LoopControl::startVideo(), Clock::stopStartStopWatch(), CameraMainWindow::stopVideoCapture(), DocumentList::storageChanged(), BenchmarkInfo::textRendering(), CameraMainWindow::timerEvent(), OContactAccessBackend_SQL::update(), Opie::OPimContactAccessBackend_SQL::update(), Clock::updateClock(), and Clock::updateLap().

QTime QTime::fromString const QString s,
Qt::DateFormat  f = Qt::TextDate
[static]
 

Returns the representation s as a QTime using the format f, or an invalid time if this is not possible.

Warning:
Note that Qt::LocalDate cannot be used here.

Definition at line 1612 of file qdatetime.cpp.

References hour(), QString::isEmpty(), Qt::LocalDate, QString::mid(), minute(), msec(), QTime(), qWarning(), and second().

Referenced by QDateTime::fromString().

int QTime::hour  )  const
 

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

Definition at line 1296 of file qdatetime.cpp.

References ds, and MSECS_PER_HOUR.

Referenced by DateBookEvent::ampmTime(), Clock::appMessage(), LauncherClock::changeTime(), DateBookDayWidget::DateBookDayWidget(), Dice::Dice(), AnalogClock::drawContents(), DateEntry::endTimeChanged(), DateEntry::eventFilter(), ServerPI::fileListing(), fromString(), OEffectiveEvent::length(), EffectiveEvent::length(), Opie::OPimOccurrence::length(), place(), QTetrix::QTetrix(), DateBookDay::relayoutPage(), TimeTabWidget::setDateTime(), OTimePickerDialog::setMinute(), OTimePicker::setMinute(), Opie::Ui::OTimePickerDialog::setMinute(), Opie::Ui::OTimePicker::setMinute(), TimeEdit::setTime(), OTimePickerDialog::setTime(), Opie::Ui::OTimePickerDialog::setTime(), OEffectiveEvent::size(), EffectiveEvent::size(), OTimePicker::slotMinute(), Opie::Ui::OTimePicker::slotMinute(), DateEntry::startTimeEdited(), TicTacGameBoard::TicTacGameBoard(), TimeString::timeString(), to_Time_t(), Opie::to_Time_t(), toString(), QDateTime::toTime_t(), Clock::updateClock(), and DateEntry::updateTimeEdit().

bool QTime::isNull  )  const [inline]
 

Returns TRUE if the time is equal to 00:00:00.000; otherwise returns FALSE. A null time is valid.

See also:
isValid()

Definition at line 129 of file qdatetime.h.

bool QTime::isValid int  h,
int  m,
int  s,
int  ms = 0
[static]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns TRUE if the specified time is valid; otherwise returns FALSE.

The time is valid if h is in the range 0..23, m and s are in the range 0..59, and ms is in the range 0..999.

Example:

    QTime::isValid(21, 10, 30); // returns TRUE
    QTime::isValid(22, 5,  62); // returns FALSE

Definition at line 1726 of file qdatetime.cpp.

bool QTime::isValid  )  const
 

Returns TRUE if the time is valid; otherwise returns FALSE. The time 23:30:55.746 is valid, whereas 24:12:30 is invalid.

See also:
isNull()

Definition at line 1286 of file qdatetime.cpp.

References ds, and MSECS_PER_DAY.

Referenced by KLocale::readTime(), TVBrowseKeyEntry::searchOnText(), setHMS(), OTimePickerDialog::setHour(), Opie::Ui::OTimePickerDialog::setHour(), OTimePickerDialog::setMinute(), Opie::Ui::OTimePickerDialog::setMinute(), Opie::Internal::OPimSortVector< T >::testTime(), TimeEdit::time(), and TVVariant::toTime().

int QTime::minute  )  const
 

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

Definition at line 1305 of file qdatetime.cpp.

References ds, MSECS_PER_HOUR, and MSECS_PER_MIN.

Referenced by DateBookEvent::ampmTime(), Clock::appMessage(), LauncherClock::changeTime(), DateBookDayWidget::DateBookDayWidget(), Dice::Dice(), AnalogClock::drawContents(), DateEntry::endTimeChanged(), DateEntry::eventFilter(), ServerPI::fileListing(), fromString(), OEffectiveEvent::length(), EffectiveEvent::length(), Opie::OPimOccurrence::length(), place(), QTetrix::QTetrix(), DateBookDay::relayoutPage(), TimeTabWidget::setDateTime(), OTimePickerDialog::setHour(), OTimePicker::setHour(), Opie::Ui::OTimePickerDialog::setHour(), Opie::Ui::OTimePicker::setHour(), TimeEdit::setTime(), OTimePickerDialog::setTime(), Opie::Ui::OTimePickerDialog::setTime(), OEffectiveEvent::size(), EffectiveEvent::size(), OTimePicker::slotHour(), Opie::Ui::OTimePicker::slotHour(), DateEntry::startTimeEdited(), TicTacGameBoard::TicTacGameBoard(), TimeString::timeString(), to_Time_t(), Opie::to_Time_t(), toString(), QDateTime::toTime_t(), Clock::updateClock(), and DateEntry::updateTimeEdit().

int QTime::msec  )  const
 

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

Definition at line 1323 of file qdatetime.cpp.

References ds.

Referenced by fromString(), and LauncherClock::timerEvent().

int QTime::msecsTo const QTime t  )  const
 

Returns the number of milliseconds from this time to t (which is negative if t is earlier than this time).

Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400 and 86400s.

See also:
secsTo()

Definition at line 1529 of file qdatetime.cpp.

References ds.

Referenced by TVVariant::closer(), elapsed(), restart(), and DataElem::toSortableQString().

bool QTime::operator!= const QTime t  )  const [inline]
 

Returns TRUE if this time is different from t; otherwise returns FALSE.

Definition at line 150 of file qdatetime.h.

References ds.

bool QTime::operator< const QTime t  )  const [inline]
 

Returns TRUE if this time is earlier than t; otherwise returns FALSE.

Definition at line 151 of file qdatetime.h.

References ds.

bool QTime::operator<= const QTime t  )  const [inline]
 

Returns TRUE if this time is earlier than or equal to t; otherwise returns FALSE.

Definition at line 152 of file qdatetime.h.

References ds.

bool QTime::operator== const QTime t  )  const [inline]
 

Returns TRUE if this time is equal to t; otherwise returns FALSE.

Definition at line 149 of file qdatetime.h.

References ds.

bool QTime::operator> const QTime t  )  const [inline]
 

Returns TRUE if this time is later than t; otherwise returns FALSE.

Definition at line 153 of file qdatetime.h.

References ds.

bool QTime::operator>= const QTime t  )  const [inline]
 

Returns TRUE if this time is later than or equal to t; otherwise returns FALSE.

Definition at line 154 of file qdatetime.h.

References ds.

int QTime::restart  ) 
 

Sets this time to the current time and returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

This function is guaranteed to be atomic and is thus very handy for repeated measurements. Call start() to start the first measurement and then restart() for each later measurement.

Note that the counter wraps to zero 24 hours after the last call to start() or restart().

Warning:
If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.
See also:
start(), elapsed(), currentTime()

Definition at line 1770 of file qdatetime.cpp.

References currentTime(), msecsTo(), and t.

Referenced by BenchmarkInfo::gfxRendering(), and LoopControl::setPosition().

int QTime::second  )  const
 

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

Definition at line 1314 of file qdatetime.cpp.

References ds, and SECS_PER_MIN.

Referenced by Dice::Dice(), AnalogClock::drawContents(), fromString(), QTetrix::QTetrix(), TimeEdit::setTime(), OEffectiveEvent::size(), EffectiveEvent::size(), TicTacGameBoard::TicTacGameBoard(), LauncherClock::timerEvent(), TimeString::timeString(), to_Time_t(), Opie::to_Time_t(), toString(), and QDateTime::toTime_t().

int QTime::secsTo const QTime t  )  const
 

Returns the number of seconds from this time to t (which is negative if t is earlier than this time).

Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400 and 86400.

See also:
addSecs() QDateTime::secsTo()

Definition at line 1490 of file qdatetime.cpp.

References ds.

Referenced by Man::Man(), Target::newTarget(), DateBookDayWidget::paintEvent(), Referee::Referee(), QDateTime::secsTo(), Man::setInitialCoords(), Man::start(), and DateEntry::startTimeChanged().

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

Sets the time to hour h, minute m, seconds s and milliseconds ms.

h must be in the range 0..23, m and s must be in the range 0..59, and ms must be in the range 0..999. Returns TRUE if the set time is valid; otherwise returns FALSE.

See also:
isValid()

Definition at line 1442 of file qdatetime.cpp.

References ds, FALSE, isValid(), MSECS_PER_DAY, qWarning(), SECS_PER_HOUR, SECS_PER_MIN, and TRUE.

Referenced by DateEntry::event(), QDateTime::fromString(), parseTime(), QTime(), OTimePickerDialog::setHour(), OTimePicker::setHour(), Opie::Ui::OTimePickerDialog::setHour(), Opie::Ui::OTimePicker::setHour(), OTimePickerDialog::setMinute(), OTimePicker::setMinute(), Opie::Ui::OTimePickerDialog::setMinute(), Opie::Ui::OTimePicker::setMinute(), OTimePicker::slotHour(), Opie::Ui::OTimePicker::slotHour(), OTimePicker::slotMinute(), Opie::Ui::OTimePicker::slotMinute(), and Event::start().

void QTime::start void   ) 
 

Sets this time to the current time. This is practical for timing:

    QTime t;
    t.start();
    some_lengthy_task();
    qDebug( "Time elapsed: %d ms", t.elapsed() );

See also:
restart(), elapsed(), currentTime()

Definition at line 1745 of file qdatetime.cpp.

References currentTime().

Referenced by StartingAppList::add(), TestItem::begin(), DateBook::DateBook(), ODateBookAccessBackend_SQL::extractUids(), OContactAccessBackend_SQL::extractUids(), OContactAccessBackend_SQL::find(), Opie::OPimContactAccessBackend_SQL::find(), BenchmarkInfo::gfxRendering(), ZCameraIO::isShutterPressed(), main(), OContactAccessBackend_SQL::OContactAccessBackend_SQL(), Opie::OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL(), OThemePixmap::OThemePixmap(), LoopControl::play(), ZCameraIO::read(), Opie::ODateBookAccessBackend_SQL::requestCustom(), OContactAccessBackend_SQL::requestCustom(), Opie::OPimContactAccessBackend_SQL::requestCustom(), OContactAccessBackend_SQL::requestNonCustom(), Opie::OPimContactAccessBackend_SQL::requestNonCustom(), Clock::resetStopWatch(), BenchmarkInfo::run(), OContactAccessBackend_SQL::sorted(), Opie::OPimContactAccessBackend_SQL::sorted(), Converter::start_conversion(), CameraMainWindow::startVideoCapture(), Clock::stopStartStopWatch(), DocumentList::storageChanged(), BenchmarkInfo::textRendering(), OContactAccessBackend_SQL::update(), Opie::OPimContactAccessBackend_SQL::update(), OThemePixmap::updateAccessed(), and Todo::TableView::updateView().

QString QTime::toString const QString format  )  const
 

Returns the time as a string. The format parameter determines the format of the result string.

These expressions may be used:

Expression Output h the hour without a leading zero (0..23 or 1..12 if AM/PM display) hh the hour with a leading zero (00..23 or 01..12 if AM/PM display) m the minute without a leading zero (0..59) mm the minute with a leading zero (00..59) s the second whithout a leading zero (0..59) ss the second whith a leading zero (00..59) z the milliseconds without leading zeroes (0..999) zzz the milliseconds with leading zeroes (000..999) AP use AM/PM display. AP will be replaced by either "AM" or "PM". ap use am/pm display. ap will be replaced by either "am" or "pm".

All other input characters will be ignored.

Example format strings (assuming that the QTime is 14:13:09.042)

Format Result hh:mm:ss.zzz 14:13:09.042 h:m:s ap 2:13:9 pm

See also:
QDate::toString() QTime::toString()

Definition at line 1426 of file qdatetime.cpp.

References fmtDateTime().

QString QTime::toString Qt::DateFormat  f = Qt::TextDate  )  const
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the time as a string. Milliseconds are not included. The f parameter determines the format of the string.

If f is Qt::TextDate, the string format is HH:MM:SS; e.g. 1 second before midnight would be "23:59:59".

If f is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates, which is also HH:MM:SS.

If f is Qt::LocalDate, the string format depends on the locale settings of the system.

Definition at line 1347 of file qdatetime.cpp.

References buf, QString::fromLocal8Bit(), QString::fromUcs2(), hour(), Qt::ISODate, Qt::LocalDate, minute(), QString::null, second(), QString::sprintf(), and Qt::TextDate.

Referenced by EmailListItem::dateFromULCString(), MLogWindow::log(), Opie::Core::odbgstream::operator<<(), IRCMessageParser::parseNumericalWhoisIdle(), Clock::setSwatchLcd(), TempScreenSaverMonitor::timerEvent(), TimeString::timeString(), and QDateTime::toString().


Friends And Related Function Documentation

QDataStream & operator<< QDataStream s,
const QTime t
[friend]
 

Writes time t to the stream s.

See also:
Format of the QDataStream operators

Definition at line 2489 of file qdatetime.cpp.

QDataStream & operator>> QDataStream s,
QTime t
[friend]
 

Reads a time from the stream s into t.

See also:
Format of the QDataStream operators

Definition at line 2502 of file qdatetime.cpp.

friend class QDateTime [friend]
 

Definition at line 172 of file qdatetime.h.


Member Data Documentation

uint QTime::ds [private]
 

Definition at line 171 of file qdatetime.h.

Referenced by addMSecs(), QDateTime::addSecs(), currentTime(), hour(), isValid(), minute(), msec(), msecsTo(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), second(), secsTo(), setHMS(), and QDateTime::setTime_t().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:49:50 2005 for OPIE by  doxygen 1.4.2