QTime more than 24 hours
-
@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
QTimewithQDateTime. 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
QTimewithQDateTime. 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.000See 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.000See 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) );
