QTime more than 24 hours
-
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 -
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@Mr_Steve said in QTime more than 24 hours:
Is there any way around the 24 hour limit in QTime?
Use
QDateTime
-
@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
withQDateTime
. See -
@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
withQDateTime
. See -
@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.
-
@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.
-
@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@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
-
@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
@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" ); }
-
@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" ); }
@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) );
-
@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) );