Search code examples
c++qtqdatetime

How to convert seconds (double) to QDateTime in Qt?


I have a number of seconds stored in a double format (but they are integer values if that's to be concerned). I would like to convert them to a hh:mm:ss format string. How to do that?

For example double secs = 120; would be 00:02:00.


Solution

  • You can create a QTime object by using its default constructor and then add your seconds to it:

    double secs = 120;
    
    QTime a(0,0,0);
    a = a.addSecs(int(secs));