Representing more than 24 hours in Qt
-
wrote on 1 Nov 2010, 14:20 last edited by
Hi all,
This is my first post to the new Qt forum! It's been a long time that I worked with Qt, good that I have chance to pick it up again :) (btw Qt Creator is awesome!)
Anyway, I am writing an application that needs to manipulate time that possibly more than 24 hours (say a duration of a sound clip could be 1 day, 15 hours and 14 mins), AFAIK QTime can only support up to 24 hours (as it means time of day), and QDateTime is representing the actual calendar date and cannot be used for this purpose.
I can't find anywhere in the API document that this could be achieved at the moment. Is it possible in Qt, other than writing my own classes to do something like:
QDateTime +/- "duration"
2010-11-01 00:00:00 + "12:00:00" = 2010-11-01 12:00:00Thanks!
-
wrote on 1 Nov 2010, 14:38 last edited by
Well, looks like you will have to have your custom type which will represent duration of clips (storing them as unsigned integers).
-
wrote on 1 Nov 2010, 15:54 last edited by
QDateTime has addSecs, addMSecs etc. I think you may use those. You only need to write a function like
@int toSecs(const QDateTime& dateTime);@ -
wrote on 1 Nov 2010, 17:11 last edited by
Q(Date)Time is a point in time, not a duration. So I would keep them separated and write a class Duration, with convenience methods converting to hh:mm:ss, total number of seconds, operator+, etc. Should be rather straightforward, as it's much simpler than points in time (which have to handle calendars, timezones, etc.).
-
wrote on 2 Nov 2010, 06:57 last edited by
Thanks all! I think I will implement a separate class for the duration purpose.
-
wrote on 2 Nov 2010, 11:46 last edited by
Could you use some timer of Qt? "http://doc.qt.nokia.com/latest/qtimer.html":http://doc.qt.nokia.com/latest/qtimer.html
@QTimer::singleShot(length_in_milliseconds, this, SLOT(trackEnded())@
Though if you seriously need to represent some arbitrary length of time, and not really time it, writing own class for it would be best way out.
-
wrote on 2 Nov 2010, 12:32 last edited by
[quote author="Smar" date="1288698360"]Could you use some timer of Qt? http://doc.qt.nokia.com/latest/qtimer.html
@QTimer::singleShot(length_in_milliseconds, this, SLOT(trackEnded())@
Though if you seriously need to represent some arbitrary length of time, and not really time it, writing own class for it would be best way out.[/quote]
I think the original intention is to represent the duration, but not measure it.
2/7