Qtimer Class
Qtimer is a timer class
It's used in three steps, creating objects, connecting signal and slot functions, start ()
Qtimer *timer = new Qtimer (this);
Connect (timer, SIGNAL (), this, SLOT (update ()));
Timer->start (1000);
where SIGNAL (timeout ()) means: Whenever the timer ends, the timer is zeroed and re-timed, and a signal activation slot function is sent.
While Timer->start (1000), 1000 of which is 1000 milliseconds, means that each timeout interval is 1000ms
If we want this timer to be timed only once, you must use the void Setsingleshot (bool singleshot) function.
Qtimer *timer = new Qtimer (this);
Connect (timer, SIGNAL (), this, SLOT (update ()));
Timer->setsetsingleshot (True)
Timer->start (60000);
This timer will only countdown for 1 minutes and then end.
Of course, we can also change the timekeeping period
void setinterval (int msec)
qtime Class
Qtime provides a time function for the user, and the difference between the Qtimer and the watch is the same as the stopwatch.
Qtime is primarily used for time operations, and he provides a number of functions that allow users to convert and calculate time.
| type |
name |
Description |
|
Qtime () |
Constructs an object with a time of 0 |
|
Qtime (int h, int m, int s = 0, int ms = 0) |
Constructs an object with an initial time |
| Qtime |
Addmsecs (int ms) const |
Increases MS milliseconds based on the current time, MS can be negative |
| Qtime |
Addsecs (int s) const |
Increase s seconds based on the current time, s can be negative |
| Int |
Hour () const |
Returns the number of hours |
| Int |
Minute () const |
Returns the number of minutes |
| Int |
Second () const |
return seconds |
| Int |
msec () const |
return milliseconds |
| bool |
IsValid () const |
Determines whether the current object's time is valid, after all, 1 days can not have 25 hours, there will not be 1 minutes 61 seconds |
| bool |
IsValid (int h, int m, int s, int ms = 0) |
Determine if the input time is valid |
| Int |
Msecsto (const QTIME & T) const |
Calculates the number of milliseconds for the distance time t, or negative if T is earlier than the current time |
| Int |
Secsto (const QTIME & T) const |
Calculate the number of seconds from the distance time t |
| bool |
SETHMS (int h, int m, int s, int ms = 0) |
Set standard HMS Time, if not compliant, return false |
|
Here are some of the most important |
|
| void |
Start () |
Record the current system time as the current time |
| Int |
Restart () |
Logs the current system time as the current time and returns the number of milliseconds between the last call to start () or the restart () function interval |
| Int |
Elapsed () const |
Calculates the number of milliseconds between the last Call Start () or the restart () function, equivalent to a timer |
| QString |
ToString (const QString & format) const |
Convert time to a specific string format |
| QString |
ToString (Qt::D ateformat format = qt::textdate) const |
by QT::D ateformat format Conversion |
| Qtime |
FromString (const QString & string, Qt::D ateformat format = qt::textdate) |
Convert from QT::D Ateformat to Qtime object |
| Qtime |
FromString (const QString & string, const QString & format) |
Convert from a specific string format to a Qtime object |
| Qtime |
CurrentTime () |
Get the current system time |
In addition, the const QString & format needs to be specifically explained in the following table:
| Expression |
Output |
| H |
The hour without a leading zero (0 to 1 if am/pm display) |
| hh |
The hour with a leading zero (xx to-or-am/pm display) |
| H |
The hour without a leading zero (0 to + even with AM/PM display) |
| HH |
The hour with a leading zero (at even with am/pm display) |
| M |
The minute without a leading zero (0 to 59) |
| Mm |
The minute with a leading zero (xx to 59) |
| S |
The second without a leading zero (0 to 59) |
| Ss |
The second with a leading zero (xx to 59) |
| Z |
The milliseconds without leading zeroes (0 to 999) |
| zzz |
The milliseconds with leading zeroes (999) |
| Ap |
Interpret as an am/pm time. AP must be either "AM" or "PM". |
| Ap |
Interpret as an am/pm time. AP must be either "AM" or "PM". |
| T |
The timezone (for example "CEST") |
Example:
| Format |
Result |
| Hh:mm:ss.zzz |
14:13:09.042 |
| H:m:s AP |
2:13:9 pm |
| H:m:s A |
14:13:9 pm |
and Qt::D Ateformat is divided into many kinds, such as qt::textdate, qt::isodate and so on, please see the official note, here is not pointed out.