QChronoTimer doesn't work as expected
-
Hello.
Qt 6.8 introduced QChronoTimer, which provides nanosecond resolution and a ±292 years range.
However, when I test it, QChronoTimer gives me the same range as QTimer, which is 25 days, regardless of my approach.
Am I doing something wrong, or is QChronoTimer broken?Code:
#include <QApplication> #include <QMainWindow> #include <QchronoTimer> #include <chrono> using namespace std::chrono; int main(int argc, char *argv[]) { QApplication app(argc, argv); QChronoTimer timer; qint64 interval = 24; timer.setInterval(days(interval)); timer.start(); qDebug("Test 1 - %lld days", duration_cast<days>(timer.remainingTime()).count()); QChronoTimer timer2; interval = 25; timer2.setInterval(days(interval)); timer2.start(); qDebug("Test 2 - %lld days", duration_cast<days>(timer2.remainingTime()).count()); QChronoTimer timer3; interval = 26; timer3.setInterval(days(interval)); timer3.start(); qDebug("Test 3 - %lld days", duration_cast<days>(timer3.remainingTime()).count()); return 0; QMainWindow window; window.show(); return app.exec(); }
Output:
Test 1 - 23 days Test 2 - -24 days Test 3 - -23 days
-
After correcting the QChronoTimer include and selecting C++20, this code works just fine for me on Linux, GCC 13.3, Qt 6.8.1.
(Compiler does throw warnings about the conversion to match the%lld
format specifier.)What platform and tool chain are you using?
-
Looking at the code I wonder why it should work for you @ChrisW67
Created a bug report at https://bugreports.qt.io/browse/QTBUG-132388
/edit: Looks like it's a windows only issue which will be fixed in the near future.
-
@Christian-Ehrlicher said in QChronoTimer doesn't work as expected:
/edit: Looks like it's a windows only issue which will be fixed in the near future.
Good, so I am not going mad then :)