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. about the longest elapsed time in Qt
Forum Updated to NodeBB v4.3 + New Features

about the longest elapsed time in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 1.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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by
    #1
    QElapsedTimer m_ElapsedTimer;
    
    if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
    {
        emit signalSendEmail();
        m_ElapsedTimer.restart();
    }
    

    i want to write like this, this will not restrict the 1st time emit, and since the 1st emit, the next emit is only allowed outof timeout milliseconds.
    However, i want the exe runs very very long time. the qinit64 seems still not that long enough for the longest interval in theory(qint64 is only about 214783 seconds). What will happen if the real time interval is longer than this?
    And what is the best method to get the longest time interval supportted in code?

    jsulmJ aha_1980A 2 Replies Last reply
    0
    • O opengpu
      QElapsedTimer m_ElapsedTimer;
      
      if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
      {
          emit signalSendEmail();
          m_ElapsedTimer.restart();
      }
      

      i want to write like this, this will not restrict the 1st time emit, and since the 1st emit, the next emit is only allowed outof timeout milliseconds.
      However, i want the exe runs very very long time. the qinit64 seems still not that long enough for the longest interval in theory(qint64 is only about 214783 seconds). What will happen if the real time interval is longer than this?
      And what is the best method to get the longest time interval supportted in code?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @opengpu said in about the longest elapsed time in Qt:

      qint64 is only about 214783 seconds

      What?
      max(qint64) == 9223372036854775807
      Divede that number by 1000 and you get the number of seconds.
      So, why do you think it is 214783 seconds?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 2 Replies Last reply
      6
      • jsulmJ jsulm

        @opengpu said in about the longest elapsed time in Qt:

        qint64 is only about 214783 seconds

        What?
        max(qint64) == 9223372036854775807
        Divede that number by 1000 and you get the number of seconds.
        So, why do you think it is 214783 seconds?

        O Offline
        O Offline
        opengpu
        wrote on last edited by
        #3

        @jsulm
        ok, that's INT_MAX, int32.
        ok, so max(int64) is about 292471208 years...that's enough

        jsulmJ 1 Reply Last reply
        0
        • jsulmJ jsulm

          @opengpu said in about the longest elapsed time in Qt:

          qint64 is only about 214783 seconds

          What?
          max(qint64) == 9223372036854775807
          Divede that number by 1000 and you get the number of seconds.
          So, why do you think it is 214783 seconds?

          O Offline
          O Offline
          opengpu
          wrote on last edited by
          #4

          @jsulm is the code above right? is it the best and efficient way?

          1 Reply Last reply
          0
          • O opengpu

            @jsulm
            ok, that's INT_MAX, int32.
            ok, so max(int64) is about 292471208 years...that's enough

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @opengpu said in about the longest elapsed time in Qt:

            ok, that's INT_MAX, int32

            This is wrong as well: max(int) = 2,147,483,647. Devide it by 1000 and you get 2,147,483sec

            "is the code above right? is it the best and efficient way?" - looks fine

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • O opengpu
              QElapsedTimer m_ElapsedTimer;
              
              if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
              {
                  emit signalSendEmail();
                  m_ElapsedTimer.restart();
              }
              

              i want to write like this, this will not restrict the 1st time emit, and since the 1st emit, the next emit is only allowed outof timeout milliseconds.
              However, i want the exe runs very very long time. the qinit64 seems still not that long enough for the longest interval in theory(qint64 is only about 214783 seconds). What will happen if the real time interval is longer than this?
              And what is the best method to get the longest time interval supportted in code?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #6

              @opengpu

              Why don't you use QTimer? Seems like the optimal tool for your case (run code every xxx seconds).

              Elapsed timer is for measurement.

              Qt has to stay free or it will die.

              O 1 Reply Last reply
              2
              • aha_1980A aha_1980

                @opengpu

                Why don't you use QTimer? Seems like the optimal tool for your case (run code every xxx seconds).

                Elapsed timer is for measurement.

                O Offline
                O Offline
                opengpu
                wrote on last edited by
                #7

                @aha_1980 i neet: donot emit signal within the time-interval

                jsulmJ 1 Reply Last reply
                0
                • O opengpu

                  @aha_1980 i neet: donot emit signal within the time-interval

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @opengpu Then emit it AFTER the time interval - for that you can use QTimer.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  O 1 Reply Last reply
                  3
                  • jsulmJ jsulm

                    @opengpu Then emit it AFTER the time interval - for that you can use QTimer.

                    O Offline
                    O Offline
                    opengpu
                    wrote on last edited by opengpu
                    #9

                    @jsulm

                    void SendEmail()
                    {
                        if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                        {
                        emit signalSendEmail();
                        m_ElapsedTimer.restart();
                        }
                    }
                    

                    SendEmail() is called at some situation, it's not called every time-interval. i just have to control inside the time-interval from last SendEmail another SendEmail is forbidden.
                    ie. SendEmail's minimun time interval, the time between two SendEmails >= this interval

                    jsulmJ KroMignonK 2 Replies Last reply
                    0
                    • O opengpu

                      @jsulm

                      void SendEmail()
                      {
                          if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                          {
                          emit signalSendEmail();
                          m_ElapsedTimer.restart();
                          }
                      }
                      

                      SendEmail() is called at some situation, it's not called every time-interval. i just have to control inside the time-interval from last SendEmail another SendEmail is forbidden.
                      ie. SendEmail's minimun time interval, the time between two SendEmails >= this interval

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @opengpu
                      ?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • O opengpu

                        @jsulm

                        void SendEmail()
                        {
                            if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                            {
                            emit signalSendEmail();
                            m_ElapsedTimer.restart();
                            }
                        }
                        

                        SendEmail() is called at some situation, it's not called every time-interval. i just have to control inside the time-interval from last SendEmail another SendEmail is forbidden.
                        ie. SendEmail's minimun time interval, the time between two SendEmails >= this interval

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #11

                        @opengpu said in about the longest elapsed time in Qt:

                        m_ElapsedTimer.restart();

                        Attention: QElapsedTimer::restart() only works if QElapsedTimer instance is valid ==> QElapsedTimer::start() has been called before!
                        If you don't use the return value (which is the elapsed timer since last start or restart), it is better to use start():

                        void MyClass::SendEmail()
                        {
                            if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                            {
                                emit signalSendEmail();
                                m_ElapsedTimer.start();
                            }
                        }
                        

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        O 1 Reply Last reply
                        4
                        • KroMignonK KroMignon

                          @opengpu said in about the longest elapsed time in Qt:

                          m_ElapsedTimer.restart();

                          Attention: QElapsedTimer::restart() only works if QElapsedTimer instance is valid ==> QElapsedTimer::start() has been called before!
                          If you don't use the return value (which is the elapsed timer since last start or restart), it is better to use start():

                          void MyClass::SendEmail()
                          {
                              if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                              {
                                  emit signalSendEmail();
                                  m_ElapsedTimer.start();
                              }
                          }
                          
                          O Offline
                          O Offline
                          opengpu
                          wrote on last edited by opengpu
                          #12

                          @KroMignon thanks so much!, so start when expired is ok?
                          because i donot when the 1st time call SendMail, so i use isValid to let me know it's the 1st time SendEmail is called.
                          after that it's actually check by the hasExpired.
                          right?

                          KroMignonK 1 Reply Last reply
                          0
                          • O opengpu

                            @KroMignon thanks so much!, so start when expired is ok?
                            because i donot when the 1st time call SendMail, so i use isValid to let me know it's the 1st time SendEmail is called.
                            after that it's actually check by the hasExpired.
                            right?

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by KroMignon
                            #13

                            @opengpu said in about the longest elapsed time in Qt:

                            so start when expired is ok?

                            Yes, of course. QElapsedTimer::hasEpired() is only a kind of helper function,
                            ==> m_ElapsedTimer.hasExpired(timeout) is almost the same as m_ElapsedTimer.elapsed() > timeout. This does not affect QElapsedTimer state.

                            The difference is only that hasExpired() will test if timer has been started (is valid).

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            O 1 Reply Last reply
                            3
                            • KroMignonK KroMignon

                              @opengpu said in about the longest elapsed time in Qt:

                              so start when expired is ok?

                              Yes, of course. QElapsedTimer::hasEpired() is only a kind of helper function,
                              ==> m_ElapsedTimer.hasExpired(timeout) is almost the same as m_ElapsedTimer.elapsed() > timeout. This does not affect QElapsedTimer state.

                              The difference is only that hasExpired() will test if timer has been started (is valid).

                              O Offline
                              O Offline
                              opengpu
                              wrote on last edited by
                              #14

                              @KroMignon thank you, and i will write as follow:

                              QElapsedTimer m_ElapsedTimer;
                              ...
                              void MyClass::SendEmail()
                              {
                                  if ( !m_ElapsedTimer.isValid() ||  m_ElapsedTimer.hasExpired(timeout))
                                  {
                                      emit signalSendEmail();
                                      m_ElapsedTimer.start();
                                  }
                              }
                              
                              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