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. Custom Time
Forum Updated to NodeBB v4.3 + New Features

Custom Time

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 1.1k Views 3 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.
  • N Offline
    N Offline
    nanamo
    wrote on 25 Jan 2020, 21:43 last edited by
    #1

    Hi
    Could you help me please,
    I know how to set the time and update it periodically using.

    tmrUpdTime = new QTimer(this);
    tmrUpdTime->setInterval(500);
    connect(tmrUpdTime, SIGNAL(timeout()), this, SLOT(updateDateTime()));
    tmrUpdTime->start();
    
    lblTime->setText(QTime::currentTime().toString(timeFormatStr));
    

    But if I accept a custom time for example 10:15 pm from user input.
    How do I start a clock counting from this point custom time-point?
    If I use above it will just call the currenttime and overwrite it to the current time.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Jan 2020, 21:49 last edited by
      #2

      Hi and welcome to devnet,

      One way would be to store the delta between the time set by the user and the system time and recalculate the value when updating.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply 25 Jan 2020, 22:42
      3
      • S SGaist
        25 Jan 2020, 21:49

        Hi and welcome to devnet,

        One way would be to store the delta between the time set by the user and the system time and recalculate the value when updating.

        N Offline
        N Offline
        nanamo
        wrote on 25 Jan 2020, 22:42 last edited by
        #3

        @SGaist thanks for the very quick reply.
        So basically implement as the code above but add or subtract an offset to the currenttime depending on the user input?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 Jan 2020, 22:46 last edited by
          #4

          That's one way to do it yes.

          Out of curiosity, what is your goal with allowing people setting arbitrary time ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply 25 Jan 2020, 23:03
          0
          • S SGaist
            25 Jan 2020, 22:46

            That's one way to do it yes.

            Out of curiosity, what is your goal with allowing people setting arbitrary time ?

            N Offline
            N Offline
            nanamo
            wrote on 25 Jan 2020, 23:03 last edited by
            #5

            @SGaist it's a project I'm working on where there is the option to set time and date within settings.
            The tablet it is been used on may not have internet access.

            So I though whatever they set it to I'll just start my clock from there.
            Kinda new to this. Is there a better way do you think?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 25 Jan 2020, 23:17 last edited by
              #6

              That still feels strange. Why would the user not change the system time in that case ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              N 1 Reply Last reply 26 Jan 2020, 08:40
              1
              • S SGaist
                25 Jan 2020, 23:17

                That still feels strange. Why would the user not change the system time in that case ?

                N Offline
                N Offline
                nanamo
                wrote on 26 Jan 2020, 08:40 last edited by
                #7

                @SGaist it will be running on a windows based tablet.
                I didn't want to mess with the system time but do
                You think this would be the way to go?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 26 Jan 2020, 12:28 last edited by
                  #8

                  Then question should rather be: why do you need that modified time in the first place ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  N 1 Reply Last reply 26 Jan 2020, 12:35
                  1
                  • S SGaist
                    26 Jan 2020, 12:28

                    Then question should rather be: why do you need that modified time in the first place ?

                    N Offline
                    N Offline
                    nanamo
                    wrote on 26 Jan 2020, 12:35 last edited by
                    #9

                    @SGaist Does not every app come with an option to alter time and date?
                    I have the user set time and date been accepted
                    Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                    J 1 Reply Last reply 26 Jan 2020, 13:33
                    0
                    • N nanamo
                      26 Jan 2020, 12:35

                      @SGaist Does not every app come with an option to alter time and date?
                      I have the user set time and date been accepted
                      Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                      J Offline
                      J Offline
                      JKSH
                      Moderators
                      wrote on 26 Jan 2020, 13:33 last edited by
                      #10

                      @nanamo said in Custom Time:

                      Does not every app come with an option to alter time and date?

                      I'm not aware of any apps that provide this option. Can you give an example?

                      Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                      When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                      Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      N S 2 Replies Last reply 26 Jan 2020, 14:02
                      3
                      • J JKSH
                        26 Jan 2020, 13:33

                        @nanamo said in Custom Time:

                        Does not every app come with an option to alter time and date?

                        I'm not aware of any apps that provide this option. Can you give an example?

                        Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                        When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                        Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                        N Offline
                        N Offline
                        nanamo
                        wrote on 26 Jan 2020, 14:02 last edited by
                        #11

                        @JKSH Brilliant, thanks a lot

                        1 Reply Last reply
                        0
                        • J JKSH
                          26 Jan 2020, 13:33

                          @nanamo said in Custom Time:

                          Does not every app come with an option to alter time and date?

                          I'm not aware of any apps that provide this option. Can you give an example?

                          Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                          When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                          Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                          S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 26 Jan 2020, 17:02 last edited by
                          #12

                          @JKSH said in Custom Time:

                          @nanamo said in Custom Time:

                          Does not every app come with an option to alter time and date?

                          I'm not aware of any apps that provide this option. Can you give an example?

                          Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                          When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                          Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                          The coded version of what I suggested in my first answer ^^

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          N J 2 Replies Last reply 26 Jan 2020, 17:44
                          3
                          • S SGaist
                            26 Jan 2020, 17:02

                            @JKSH said in Custom Time:

                            @nanamo said in Custom Time:

                            Does not every app come with an option to alter time and date?

                            I'm not aware of any apps that provide this option. Can you give an example?

                            Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                            When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                            Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                            The coded version of what I suggested in my first answer ^^

                            N Offline
                            N Offline
                            nanamo
                            wrote on 26 Jan 2020, 17:44 last edited by
                            #13

                            @SGaist Yes, thanks to all.
                            I will try now and see how it goes

                            1 Reply Last reply
                            0
                            • S SGaist
                              26 Jan 2020, 17:02

                              @JKSH said in Custom Time:

                              @nanamo said in Custom Time:

                              Does not every app come with an option to alter time and date?

                              I'm not aware of any apps that provide this option. Can you give an example?

                              Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()

                              When your user sets a custom time, calculate the difference between the custom time and the system clock (QTime::currentTime()). Record this difference (also known as the offset).

                              Then, whenever you need to calculate or display the time, add the offset to the system time: QTime::currentTime().addSecs(offset).

                              The coded version of what I suggested in my first answer ^^

                              J Offline
                              J Offline
                              JKSH
                              Moderators
                              wrote on 26 Jan 2020, 23:38 last edited by
                              #14

                              @SGaist said in Custom Time:

                              The coded version of what I suggested in my first answer ^^

                              Ack, I didn't read the thread carefully; sorry!

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              S 1 Reply Last reply 27 Jan 2020, 07:04
                              0
                              • J JKSH
                                26 Jan 2020, 23:38

                                @SGaist said in Custom Time:

                                The coded version of what I suggested in my first answer ^^

                                Ack, I didn't read the thread carefully; sorry!

                                S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 27 Jan 2020, 07:04 last edited by
                                #15

                                @JKSH said in Custom Time:

                                @SGaist said in Custom Time:

                                The coded version of what I suggested in my first answer ^^

                                Ack, I didn't read the thread carefully; sorry!

                                No worries ! I just found it funny :-D

                                You made my point clearer so @nanamo has understood it better so it's all good :-)

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0

                                8/15

                                26 Jan 2020, 12:28

                                • Login

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