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. QTime more than 24 hours
QtWS25 Last Chance

QTime more than 24 hours

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 2.3k 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.
  • M Offline
    M Offline
    Mr_Steve
    wrote on last edited by
    #1

    Hello,
    Is there any way around the 24 hour limit in QTime?
    There is such a code:

    QVector<QTime> time;
            time.fill( QTime(0,0), 3 );
    
            while ( q.next() )
            {
                ms = MachineState( q.value(2).toInt(), 0, 0, q.value(0).toDateTime() );
                int interval = lastMs.date().secsTo( ms.date() );
                switch ( lastMs.state() )
                {
                case MachineState::work :
                    time[MachineState::work] = time[MachineState::work].addSecs(interval);
                    break;
                case MachineState::adjustment :
                    time[MachineState::adjustment] = time[MachineState::adjustment].addSecs(interval);
                    break;
                case MachineState::idle :
                    time[MachineState::idle] = time[MachineState::idle].addSecs(interval);
                    break;
                }
                lastMs = ms;
            }
    

    If you process information in 2-3 days, the timer will simply reset, how can I get around this?
    QT 4.7.0

    JKSHJ 1 Reply Last reply
    0
    • M Mr_Steve

      Hello,
      Is there any way around the 24 hour limit in QTime?
      There is such a code:

      QVector<QTime> time;
              time.fill( QTime(0,0), 3 );
      
              while ( q.next() )
              {
                  ms = MachineState( q.value(2).toInt(), 0, 0, q.value(0).toDateTime() );
                  int interval = lastMs.date().secsTo( ms.date() );
                  switch ( lastMs.state() )
                  {
                  case MachineState::work :
                      time[MachineState::work] = time[MachineState::work].addSecs(interval);
                      break;
                  case MachineState::adjustment :
                      time[MachineState::adjustment] = time[MachineState::adjustment].addSecs(interval);
                      break;
                  case MachineState::idle :
                      time[MachineState::idle] = time[MachineState::idle].addSecs(interval);
                      break;
                  }
                  lastMs = ms;
              }
      

      If you process information in 2-3 days, the timer will simply reset, how can I get around this?
      QT 4.7.0

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Mr_Steve said in QTime more than 24 hours:

      Is there any way around the 24 hour limit in QTime?

      Use QDateTime

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

      1 Reply Last reply
      3
      • M Offline
        M Offline
        Mr_Steve
        wrote on last edited by
        #3

        Сould you give an example?

        JKSHJ 1 Reply Last reply
        0
        • M Mr_Steve

          Сould you give an example?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Mr_Steve said in QTime more than 24 hours:

          Сould you give an example?

          What kind of example do you want?

          In your code, replace QTime with QDateTime. See

          • https://doc.qt.io/archives/qt-4.7/qtime.html
          • https://doc.qt.io/archives/qt-4.7/qdatetime.html

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

          M 1 Reply Last reply
          2
          • JKSHJ JKSH

            @Mr_Steve said in QTime more than 24 hours:

            Сould you give an example?

            What kind of example do you want?

            In your code, replace QTime with QDateTime. See

            • https://doc.qt.io/archives/qt-4.7/qtime.html
            • https://doc.qt.io/archives/qt-4.7/qdatetime.html
            M Offline
            M Offline
            Mr_Steve
            wrote on last edited by
            #5

            @JKSH If i replace QTime with QDateTime i got crash in app.

            JKSHJ 1 Reply Last reply
            0
            • M Mr_Steve

              @JKSH If i replace QTime with QDateTime i got crash in app.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @Mr_Steve said in QTime more than 24 hours:

              i got crash

              Start debugging.

              QTime is limited to 24 hours. QDateTime is limited to thousands of years.

              You asked how you can overcome the 24-hour limit. The answer is to use QDateTime instead of QTime.

              However, don't just automatically replace all instances of QTime with QDateTime; check each QTime object and see if you need to change your code around it.

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

              M 1 Reply Last reply
              6
              • JKSHJ JKSH

                @Mr_Steve said in QTime more than 24 hours:

                i got crash

                Start debugging.

                QTime is limited to 24 hours. QDateTime is limited to thousands of years.

                You asked how you can overcome the 24-hour limit. The answer is to use QDateTime instead of QTime.

                However, don't just automatically replace all instances of QTime with QDateTime; check each QTime object and see if you need to change your code around it.

                M Offline
                M Offline
                Mr_Steve
                wrote on last edited by Mr_Steve
                #7

                @JKSH
                Suppose I need QDateTime to start at 00:00:00 and read further
                Should I set the date using QDateTime :: FromString?
                Just by changing the QDateTime to get a year -4763

                JKSHJ 1 Reply Last reply
                0
                • M Mr_Steve

                  @JKSH
                  Suppose I need QDateTime to start at 00:00:00 and read further
                  Should I set the date using QDateTime :: FromString?
                  Just by changing the QDateTime to get a year -4763

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @Mr_Steve said in QTime more than 24 hours:

                  @JKSH
                  Suppose I need QDateTime to start at 00:00:00 and read further
                  Should I set the date using QDateTime :: FromString?

                  Yes, you can use QDateTime::fromString().

                  You can also use the QDateTime constructor. For example,

                  QDateTime dt( QDate::currentDate() );
                  // dt.date() == Today's date
                  // dt.time() == 00:00:00.000
                  

                  See https://doc.qt.io/archives/qt-4.7/qdatetime.html#QDateTime-2

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

                  M 1 Reply Last reply
                  4
                  • JKSHJ JKSH

                    @Mr_Steve said in QTime more than 24 hours:

                    @JKSH
                    Suppose I need QDateTime to start at 00:00:00 and read further
                    Should I set the date using QDateTime :: FromString?

                    Yes, you can use QDateTime::fromString().

                    You can also use the QDateTime constructor. For example,

                    QDateTime dt( QDate::currentDate() );
                    // dt.date() == Today's date
                    // dt.time() == 00:00:00.000
                    

                    See https://doc.qt.io/archives/qt-4.7/qdatetime.html#QDateTime-2

                    M Offline
                    M Offline
                    Mr_Steve
                    wrote on last edited by
                    #9

                    @JKSH Next i try to show the time in the table, but get empty cells

                    Here is code:

                    list << QString()
                                << _machines[ i + 1 ]                     
                                << Table::toStr( time.at(0) )					
                                << Table::toStr( time.at(1) ) 				
                                << Table::toStr( time.at(2) )
                    
                     QString inline toStr(const QDateTime & dt)
                        { return dt.toString( "yyyy-MM-dd hh:mm:ss" ); }
                    
                        QString inline toStr(const QTime & dt)
                        { return dt.toString( "HH:mm" ); }
                    
                        QString inline toStr(const QDate & dt)
                        { return dt.toString( "yyyy-MM-dd" ); }
                    
                    JKSHJ 1 Reply Last reply
                    0
                    • M Mr_Steve

                      @JKSH Next i try to show the time in the table, but get empty cells

                      Here is code:

                      list << QString()
                                  << _machines[ i + 1 ]                     
                                  << Table::toStr( time.at(0) )					
                                  << Table::toStr( time.at(1) ) 				
                                  << Table::toStr( time.at(2) )
                      
                       QString inline toStr(const QDateTime & dt)
                          { return dt.toString( "yyyy-MM-dd hh:mm:ss" ); }
                      
                          QString inline toStr(const QTime & dt)
                          { return dt.toString( "HH:mm" ); }
                      
                          QString inline toStr(const QDate & dt)
                          { return dt.toString( "yyyy-MM-dd" ); }
                      
                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @Mr_Steve said in QTime more than 24 hours:

                      i try to show the time in the table

                      Learn to use QDebug. It will help you see your data.

                      #include <QDebug>
                      
                      ...
                      
                      qDebug() << time.at(0);
                      qDebug() << Table::toStr( time.at(0) );
                      

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

                      M 1 Reply Last reply
                      3
                      • JKSHJ JKSH

                        @Mr_Steve said in QTime more than 24 hours:

                        i try to show the time in the table

                        Learn to use QDebug. It will help you see your data.

                        #include <QDebug>
                        
                        ...
                        
                        qDebug() << time.at(0);
                        qDebug() << Table::toStr( time.at(0) );
                        
                        M Offline
                        M Offline
                        Mr_Steve
                        wrote on last edited by
                        #11

                        @JKSH 872c4319-e8ac-4939-9df3-f2c91467c668-image.png

                        JKSHJ 1 Reply Last reply
                        0
                        • M Mr_Steve

                          @JKSH 872c4319-e8ac-4939-9df3-f2c91467c668-image.png

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          @Mr_Steve Your date looks like it contains corrupted or uninitialized data.

                          Debug your program at the point where you create the QDateTime objects.

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

                          1 Reply Last reply
                          2

                          • Login

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