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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      3
      • SGaistS SGaist

        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 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          0
          • SGaistS SGaist

            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 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              1
              • SGaistS SGaist

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

                N Offline
                N Offline
                nanamo
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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
                  1
                  • SGaistS SGaist

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

                    N Offline
                    N Offline
                    nanamo
                    wrote on 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()

                    JKSHJ 1 Reply Last reply
                    0
                    • N nanamo

                      @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()

                      JKSHJ Online
                      JKSHJ Online
                      JKSH
                      Moderators
                      wrote on 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 SGaistS 2 Replies Last reply
                      3
                      • JKSHJ JKSH

                        @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 last edited by
                        #11

                        @JKSH Brilliant, thanks a lot

                        1 Reply Last reply
                        0
                        • JKSHJ JKSH

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

                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 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 JKSHJ 2 Replies Last reply
                          3
                          • SGaistS SGaist

                            @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 last edited by
                            #13

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

                            1 Reply Last reply
                            0
                            • SGaistS SGaist

                              @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 ^^

                              JKSHJ Online
                              JKSHJ Online
                              JKSH
                              Moderators
                              wrote on 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

                              SGaistS 1 Reply Last reply
                              0
                              • JKSHJ JKSH

                                @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!

                                SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 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

                                • Login

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