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. Adding / appending two QTimes together
Forum Updated to NodeBB v4.3 + New Features

Adding / appending two QTimes together

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.4k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    I have two times, and I was wondering if QTime has the functionality to add or append times together.

    For example:
    I have 2 QStrings in the format 00:00:04 and 00:01:03 where the format is hour:minutes:seconds. If I convert them to a QTime and add them, i want the result to be 00:01:07 then convert it to a QString. I can attempt to do some wicked string processing but I am just curious if I could do this easily with QTime.

    Thanks in advance!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You might be interested in the threads with the "tag QTimeSpan":https://qt-project.org/search/tag/qtimespan

      Otherwise it could be possible to convert your strings to QTime convert this secons and the conversion back. Problems may occur when passing the 24 hour mark.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        koahnig is right, you need something like QTimeSpan for that. Unfortunately, we've not been able to land that in Qt proper yet. Sorry about that! The sources are available though, and with a few tweaks (move the definition of some enums to the class itself) it should pose no big problem to compile into your own application. I do that myself.

        The issue you're facing is that QTime does not represent a length of time, but a point in time. That is an important distinction. Compare it with the distinction between a location (where you are) to a distance (between where you are and the fridge with your nice cool beer). They are different (yet related) concepts. In terms of time: your age is not the same as your birth date.

        QTimeSpan models the concept of a length of time, while QTime, QDate and QDateTime model a point in time. For points in time or space, the concept of adding or substracting them does not make sense, at least not if you expect the result to be another such point. QTimeSpan however defines the concept of substracting two dates or times to yield a time span, and it defines the natural operations like addition, substraction and multiplication, as well as operations like intersection and unions on time spans.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vezprog
          wrote on last edited by
          #4

          I see! Thank you for the detailed description, I will download the sources and give it a try!

          I've seen a lot of posts about QTimeSpan, hope it gets put into the Qt 4.8 soon.

          Thanks again guys.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            QTimeSpan will not appear in Qt 4.8. There will only be bugfix updates for this series. It is also unlikely there will ever be a 4.9. Also, it will not be in Qt 5.0, as the feature freeze for 5.0 has already passed. So, the first version it might appear in, is in Qt 5.1. There is no planning yet when that version will appear.

            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