Results 1 to 5 of 5

Thread: QTime to a format which I can use in a calculation

  1. #1
    Join Date
    Aug 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTime to a format which I can use in a calculation

    Hello,

    I am putting QTime values in my SQLite database however, it represents a duration which I want to use as part of a calculation (Speed = Distance / Time).

    What would be the best format to convert (and an example would be greatly appreciated, though not necessary) to convert the QTime into a data type suitable for the calculation.

    I have been looking at the documentation though I am unsure of which methods to use and what would be best.

    Thank you for any help or advice you can offer!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTime to a format which I can use in a calculation

    QDateTime.toTime_t() returns the instant as the number of seconds since the Unix epoch began. Or, you can combine QDate.JulianDate() with QTime.msec() to form a floating point number that can be subtracted from a similar construct to yield a duration spanning any two arbitrary dates.

  3. #3
    Join Date
    Aug 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTime to a format which I can use in a calculation

    Thank you!

    The thing is though, the time registered is a duration, for example 01:27:03 is 1 hour, 27 mins and 3 seconds.

    I would like to convert this into something similar to the UNIX epoch time but the number of seconds passed since 00:00:00, in this case 5223.

  4. #4
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: QTime to a format which I can use in a calculation

    Try read Qt documentation before ask stupid question.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTime to a format which I can use in a calculation

    The obvious choice is to convert it to seconds or miliseconds. If you can't find the right method then just use your head and do the calculation manually, I'm sure you can calculate how many seconds makes one hour.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTime
    By dragon in forum Newbie
    Replies: 12
    Last Post: 16th February 2012, 10:40
  2. QTime error?
    By roxton in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 22:06
  3. QTime
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 05:21
  4. QTime restart
    By jhowland in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2008, 20:18
  5. Extending QDate, QTime and QDateTime
    By jamadagni in forum Qt Programming
    Replies: 8
    Last Post: 24th March 2006, 15:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.