Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Representing more than 24 hours in Qt
QtWS25 Last Chance

Representing more than 24 hours in Qt

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patap
    wrote on last edited by
    #1

    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:00

    Thanks!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lyuts
      wrote on last edited by
      #2

      Well, looks like you will have to have your custom type which will represent duration of clips (storing them as unsigned integers).

      I'm a rebel in the S.D.G.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckakman
        wrote on last edited by
        #3

        QDateTime has addSecs, addMSecs etc. I think you may use those. You only need to write a function like
        @int toSecs(const QDateTime& dateTime);@

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Frank
          wrote on last edited by
          #4

          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.).

          1 Reply Last reply
          0
          • P Offline
            P Offline
            patap
            wrote on last edited by
            #5

            Thanks all! I think I will implement a separate class for the duration purpose.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Smar
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lyuts
                wrote on last edited by
                #7

                [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.

                I'm a rebel in the S.D.G.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved