Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1953

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/tools/qdatetime.cpp:1103 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QTime Class</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QTime Class Reference</h1>

<p>The QTime class provides clock time functions.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qdatetime-h.html">qdatetime.h</a>&gt;</tt>
<p><a href="qtime-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QTime"><b>QTime</b></a> ()</div></li>
<li><div class=fn><a href="#QTime-2"><b>QTime</b></a> ( int&nbsp;h, int&nbsp;m, int&nbsp;s = 0, int&nbsp;ms = 0 )</div></li>
<li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</div></li>
<li><div class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</div></li>
<li><div class=fn>int <a href="#hour"><b>hour</b></a> () const</div></li>
<li><div class=fn>int <a href="#minute"><b>minute</b></a> () const</div></li>
<li><div class=fn>int <a href="#second"><b>second</b></a> () const</div></li>
<li><div class=fn>int <a href="#msec"><b>msec</b></a> () const</div></li>
<li><div class=fn>QString <a href="#toString-2"><b>toString</b></a> ( Qt::DateFormat&nbsp;f = Qt::TextDate ) const</div></li>
<li><div class=fn>QString <a href="#toString"><b>toString</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;format ) const</div></li>
<li><div class=fn>bool <a href="#setHMS"><b>setHMS</b></a> ( int&nbsp;h, int&nbsp;m, int&nbsp;s, int&nbsp;ms = 0 )</div></li>
<li><div class=fn>QTime <a href="#addSecs"><b>addSecs</b></a> ( int&nbsp;nsecs ) const</div></li>
<li><div class=fn>int <a href="#secsTo"><b>secsTo</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>QTime <a href="#addMSecs"><b>addMSecs</b></a> ( int&nbsp;ms ) const</div></li>
<li><div class=fn>int <a href="#msecsTo"><b>msecsTo</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator-lt"><b>operator&lt;</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator-lt-eq"><b>operator&lt;=</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator-gt"><b>operator&gt;</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>bool <a href="#operator-gt-eq"><b>operator&gt;=</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;t ) const</div></li>
<li><div class=fn>void <a href="#start"><b>start</b></a> ()</div></li>
<li><div class=fn>int <a href="#restart"><b>restart</b></a> ()</div></li>
<li><div class=fn>int <a href="#elapsed"><b>elapsed</b></a> () const</div></li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li><div class=fn>QTime <a href="#currentTime"><b>currentTime</b></a> ()</div></li>
<li><div class=fn>QTime <a href="#fromString"><b>fromString</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;s, Qt::DateFormat&nbsp;f = Qt::TextDate )</div></li>
<li><div class=fn>bool <a href="#isValid-2"><b>isValid</b></a> ( int&nbsp;h, int&nbsp;m, int&nbsp;s, int&nbsp;ms = 0 )</div></li>
</ul>
<h2>Related Functions</h2>
<ul>
<li><div class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QTime&nbsp;&amp;&nbsp;t )</div></li>
<li><div class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QTime&nbsp;&amp;&nbsp;t )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


<p> The QTime class provides clock time functions.
<p> 

<p> 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.
<p> QTime operates with 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.
<p> A QTime object is typically created either by giving the number of
hours, minutes, seconds, and milliseconds explicitly, or by using
the static function <a href="#currentTime">currentTime</a>(), which makes 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.
<p> The <a href="#hour">hour</a>(), <a href="#minute">minute</a>(), <a href="#second">second</a>(), and <a href="#msec">msec</a>() 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
<a href="#toString">toString</a>() function.
<p> 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.
<p> The time a given number of seconds or milliseconds later than a
given time can be found using the <a href="#addSecs">addSecs</a>() or <a href="#addMSecs">addMSecs</a>()
functions. Correspondingly, the number of (milli)seconds between two
times can be found using the <a href="#secsTo">secsTo</a>() or <a href="#msecsTo">msecsTo</a>() functions.
<p> QTime can be used to measure a span of elapsed time using the
<a href="#start">start</a>(), <a href="#restart">restart</a>(), and <a href="#elapsed">elapsed</a>() functions.
<p> <p>See also <a href="qdate.html">QDate</a>, <a href="qdatetime.html">QDateTime</a> and <a href="time.html">Time and Date</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QTime"></a>QTime::QTime ()
</h3>

<p> Constructs the time 0 hours, minutes, seconds and milliseconds,
i.e. 00:00:00.000 (midnight). This is a valid time.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn><a name="QTime-2"></a>QTime::QTime ( int&nbsp;h, int&nbsp;m, int&nbsp;s = 0, int&nbsp;ms = 0 )
</h3>
Constructs a time with hour <em>h</em>, minute <em>m</em>, seconds <em>s</em> and
milliseconds <em>ms</em>.
<p> <em>h</em> must be in the range 0..23, <em>m</em> and <em>s</em> must be in the range
0..59, and <em>ms</em> must be in the range 0..999.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn><a href="qtime.html">QTime</a> <a name="addMSecs"></a>QTime::addMSecs ( int&nbsp;ms ) const
</h3>
Returns a QTime object containing a time <em>ms</em> milliseconds later than
the time of this object (or earlier if <em>ms</em> is negative).
<p> Note that the time will wrap if it passes midnight. See <a href="#addSecs">addSecs</a>()
for an example.
<p> <p>See also <a href="#addSecs">addSecs</a>() and <a href="#msecsTo">msecsTo</a>().

<h3 class=fn><a href="qtime.html">QTime</a> <a name="addSecs"></a>QTime::addSecs ( int&nbsp;nsecs ) const
</h3>
Returns a QTime object containing a time <em>nsecs</em> seconds later than
the time of this object (or earlier if <em>nsecs</em> is negative).
<p> Note that the time will wrap if it passes midnight.
<p> Example:
<pre>
    QTime n( 14, 0, 0 );                // n == 14:00:00
    QTime t;
    t = n.<a href="#addSecs">addSecs</a>( 70 );                // t == 14:01:10
    t = n.<a href="#addSecs">addSecs</a>( -70 );               // t == 13:58:50
    t = n.<a href="#addSecs">addSecs</a>( 10*60*60 + 5 );      // t == 00:00:05
    t = n.<a href="#addSecs">addSecs</a>( -15*60*60 );         // t == 23:00:00
  </pre>
 
<p> <p>See also <a href="#addMSecs">addMSecs</a>(), <a href="#secsTo">secsTo</a>() and <a href="qdatetime.html#addSecs">QDateTime::addSecs</a>().

<h3 class=fn><a href="qtime.html">QTime</a> <a name="currentTime"></a>QTime::currentTime ()<tt> [static]</tt>
</h3>
Returns the current time as reported by the system clock.
<p> Note that the accuracy depends on the accuracy of the underlying
operating system; not all systems provide 1-millisecond accuracy.

<p>Examples: <a href="aclock-example.html#x2077">aclock/aclock.cpp</a>, <a href="dclock-example.html#x1766">dclock/dclock.cpp</a>, <a href="t12.html#x2211">t12/cannon.cpp</a> and <a href="tictac-example.html#x194">tictac/tictac.cpp</a>.
<h3 class=fn>int <a name="elapsed"></a>QTime::elapsed () const
</h3>
Returns the number of milliseconds that have elapsed since the last
time <a href="#start">start</a>() or <a href="#restart">restart</a>() was called.
<p> Note that the counter wraps to zero 24 hours after the last call to
start() or restart.
<p> Note that the accuracy depends on the accuracy of the underlying
operating system; not all systems provide 1-millisecond accuracy.
<p> <b>Warning:</b> 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.
<p> <p>See also <a href="#start">start</a>() and <a href="#restart">restart</a>().

<h3 class=fn><a href="qtime.html">QTime</a> <a name="fromString"></a>QTime::fromString ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;s, <a href="qt.html#DateFormat-enum">Qt::DateFormat</a>&nbsp;f = Qt::TextDate )<tt> [static]</tt>
</h3>
Returns the representation <em>s</em> as a QTime using the format <em>f</em>, or
an invalid time if this is not possible.
<p> Note that Qt::LocalDate cannot be used here.

<h3 class=fn>int <a name="hour"></a>QTime::hour () const
</h3>
Returns the hour part (0..23) of the time.

<p>Example: <a href="tictac-example.html#x195">tictac/tictac.cpp</a>.
<h3 class=fn>bool <a name="isNull"></a>QTime::isNull () const
</h3>

Returns TRUE if the time is equal to 00:00:00.000; otherwise returns FALSE.
A null time is valid.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn>bool <a name="isValid"></a>QTime::isValid () const
</h3>
Returns TRUE if the time is valid; otherwise returns FALSE.
The time 23:30:55.746 is valid, whereas 24:12:30 is invalid.
<p> <p>See also <a href="#isNull">isNull</a>().

<h3 class=fn>bool <a name="isValid-2"></a>QTime::isValid ( int&nbsp;h, int&nbsp;m, int&nbsp;s, int&nbsp;ms = 0 )<tt> [static]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns TRUE if the specified time is valid; otherwise returns FALSE.
<p> The time is valid if <em>h</em> is in the range 0..23, <em>m</em> and <em>s</em> are in
the range 0..59, and <em>ms</em> is in the range 0..999.
<p> Example:
<pre>
    QTime::<a href="#isValid">isValid</a>(21, 10, 30); // returns TRUE
    QTime::<a href="#isValid">isValid</a>(22, 5,  62); // returns FALSE
  </pre>
 

<h3 class=fn>int <a name="minute"></a>QTime::minute () const
</h3>
Returns the minute part (0..59) of the time.

<p>Examples: <a href="aclock-example.html#x2078">aclock/aclock.cpp</a> and <a href="tictac-example.html#x196">tictac/tictac.cpp</a>.
<h3 class=fn>int <a name="msec"></a>QTime::msec () const
</h3>
Returns the millisecond part (0..999) of the time.

<h3 class=fn>int <a name="msecsTo"></a>QTime::msecsTo ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>
Returns the number of milliseconds from this time to <em>t</em> (which is
negative if <em>t</em> is earlier than this time).
<p> Because QTime measures time within a day and there are 86400
seconds in a day, the result is between -86400 and 86400s.
<p> <p>See also <a href="#secsTo">secsTo</a>().

<h3 class=fn>bool <a name="operator!-eq"></a>QTime::operator!= ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is different from <em>t</em>; otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-lt"></a>QTime::operator&lt; ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is earlier than <em>t</em>; otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-lt-eq"></a>QTime::operator&lt;= ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is earlier than or equal to <em>t</em>;
otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-eq-eq"></a>QTime::operator== ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is equal to <em>t</em>; otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-gt"></a>QTime::operator&gt; ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is later than <em>t</em>; otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-gt-eq"></a>QTime::operator&gt;= ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>

<p> Returns TRUE if this time is later than or equal to <em>t</em>; otherwise
returns FALSE.

<h3 class=fn>int <a name="restart"></a>QTime::restart ()
</h3>
Sets this time to the current time and returns the number of
milliseconds that have elapsed since the last time <a href="#start">start</a>() or
<a href="#restart">restart</a>() was called.
<p> 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.
<p> Note that the counter wraps to zero 24 hours after the last call to
start() or restart().
<p> <b>Warning:</b> 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.
<p> <p>See also <a href="#start">start</a>(), <a href="#elapsed">elapsed</a>() and <a href="#currentTime">currentTime</a>().

<h3 class=fn>int <a name="second"></a>QTime::second () const
</h3>
Returns the second part (0..59) of the time.

<p>Example: <a href="tictac-example.html#x197">tictac/tictac.cpp</a>.
<h3 class=fn>int <a name="secsTo"></a>QTime::secsTo ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t ) const
</h3>
Returns the number of seconds from this time to <em>t</em> (which is
negative if <em>t</em> is earlier than this time).
<p> Because QTime measures time within a day and there are 86400 seconds
in a day, the result is between -86400 and 86400.
<p> <p>See also <a href="#addSecs">addSecs</a>() and <a href="qdatetime.html#secsTo">QDateTime::secsTo</a>().

<p>Example: <a href="t12.html#x2212">t12/cannon.cpp</a>.
<h3 class=fn>bool <a name="setHMS"></a>QTime::setHMS ( int&nbsp;h, int&nbsp;m, int&nbsp;s, int&nbsp;ms = 0 )
</h3>
Sets the time to hour <em>h</em>, minute <em>m</em>, seconds <em>s</em> and
milliseconds <em>ms</em>.
<p> <em>h</em> must be in the range 0..23, <em>m</em> and <em>s</em> must be in the range
0..59, and <em>ms</em> must be in the range 0..999. Returns TRUE if the set
time is valid; otherwise returns FALSE.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn>void <a name="start"></a>QTime::start ()
</h3>
Sets this time to the current time. This is practical for timing:
<p> <pre>
    QTime t;
    t.<a href="#start">start</a>();                     // start clock
    ... // some lengthy task
    <a href="qapplication.html#qDebug">qDebug</a>( "%d\n", t.<a href="#elapsed">elapsed</a>() ); // prints the number of msecs elapsed
  </pre>
 
<p> <p>See also <a href="#restart">restart</a>(), <a href="#elapsed">elapsed</a>() and <a href="#currentTime">currentTime</a>().

<h3 class=fn><a href="qstring.html">QString</a> <a name="toString"></a>QTime::toString ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;format ) const
</h3>  Returns the time as a string.  The <em>format</em> parameter determines
the format of the result string.
<p> These expressions may be used:
<p> <ul>
<li> <em>h</em> - the hour without a leading zero (0..23 or 1..12 if AM/PM display)
<li> <em>hh</em> - the hour with a leading zero (00..23 or 01..12 if AM/PM display)
<li> <em>m</em> - the minute without a leading zero (0..59)
<li> <em>mm</em> - the minute with a leading zero (00..59)
<li> <em>s</em> - the second whithout a leading zero (0..59)
<li> <em>ss</em> - the second whith a leading zero (00..59)
<li> <em>z</em> - the milliseconds without leading zeroes (0..999)
<li> <em>zzz</em> - the milliseconds with leading zeroes (000..999)
<li> <em>AP</em> - switch to AM/PM display. <em>AP</em> will be replaced by either "AM" or "PM".
<li> <em>ap</em> - switch to am/pm display. <em>ap</em> will be replaced by either "am" or "pm".
</ul>
<p> All other input characters will be ignored.
<p> Example format Strings (assuming that the QTime is 14:13:09.042)
<p> <ul>
<li> "hh:mm:ss.zzz"  will result in "14:13:09.042"
<li> "h:m:s ap" will result in "2:13:9 pm"
</ul>
<p> <p>See also <a href="qdate.html#toString">QDate::toString</a>() and <a href="#toString">QTime::toString</a>().

<p> 
<h3 class=fn><a href="qstring.html">QString</a> <a name="toString-2"></a>QTime::toString ( <a href="qt.html#DateFormat-enum">Qt::DateFormat</a>&nbsp;f = Qt::TextDate ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the time as a string.  Milliseconds are not included.
The <em>f</em> parameter determines the format of the string.
<p> If <em>f</em> is Qt::TextDate, the string format is HH:MM:SS; e.g. 1
second before midnight would be "23:59:59".
<p> If <em>f</em> is Qt::ISODate, the string format corresponds to the ISO
8601 specification for representations of dates, which is also
HH:MM:SS.
<p> If <em>f</em> is Qt::LocalDate, the string format depends on the locale
settings of the system.

<hr><h2>Related Functions</h2>
<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t )
</h3>

Writes time <em>t</em> to the stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;t )
</h3>

Reads a time from the stream <em>s</em> into <em>t</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>