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. QChronoTimer doesn't work as expected
Forum Updated to NodeBB v4.3 + New Features

QChronoTimer doesn't work as expected

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 528 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.
  • I Offline
    I Offline
    IlyaLts
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #3

        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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          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.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @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 :)

          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