QTime is a class in Qt library which is used to represent time in hours, minutes, seconds and milliseconds. It provides a set of functions to manipulate and retrieve time values.
Here are some examples of how to use QTime in C++:
1. To retrieve the current time:
```c++ #include #include
int main() { QTime currentTime = QTime::currentTime(); qDebug() << "Current time is: " << currentTime.toString(); return 0; }
The output of this code will be the current time in HH:mm:ss format.
2. To retrieve the hour of current time:
c++ #include #include
int main() { QTime currentTime = QTime::currentTime(); int hour = currentTime.hour(); qDebug() << "Hour of current time is: " << hour; return 0; }
The output of this code will be the current hour value.
3. To set the time:
c++
#include
#include
int main()
{
QTime newTime = QTime(12, 30, 0);
qDebug() << "New time is: " << newTime.toString();
return 0;
}
```
This code will set the time to 12:30:00 and print it on the console.
The package/library used in these examples is Qt.
C++ (Cpp) QTime::hour - 30 examples found. These are the top rated real world C++ (Cpp) examples of QTime::hour extracted from open source projects. You can rate examples to help us improve the quality of examples.