Results 1 to 3 of 3

Thread: QElapsedTimer::elapsed() restarts after ~11000ms on WinXP Home SP3

  1. #1
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QElapsedTimer::elapsed() restarts after ~11000ms on WinXP Home SP3

    Hello,
    QElapsedTimer::elapsed() always restarts after ~11000ms on Windows XP Home SP3 and Qt 4.8. On Qt 4.7.4 is OK.
    Can anyone confirm this?

    Example code:

    main_window.cpp:
    Qt Code:
    1. #include "main_window.h"
    2. #include <QTimer>
    3. #include <QMessageBox>
    4. #include <QDebug>
    5.  
    6. main_window::main_window(QWidget * parent) :
    7. QMainWindow(parent)
    8. {
    9. ui.setupUi(this);
    10.  
    11. refresh_timer = new QTimer(this);
    12. refresh_timer->setInterval(1000);
    13. connect(refresh_timer, SIGNAL(timeout()), SLOT(refresh_ui()));
    14.  
    15. const int clock_type = QElapsedTimer::clockType();
    16. const bool is_monotonic = QElapsedTimer::isMonotonic();
    17. qDebug() << "QElapsedTimer::clockType() = " << clock_type;
    18. qDebug() << "isMonotonic: " << is_monotonic;
    19.  
    20. QMessageBox::information(this, "info",
    21. QString("QElapsedTimer::clockType() = %1\n"
    22. "isMonotonic: %2")
    23. .arg(QString::number(clock_type), is_monotonic ? "true" : "false"));
    24.  
    25. elapsed_timer.start();
    26. refresh_timer->start();
    27. }
    28.  
    29. void main_window::refresh_ui()
    30. {
    31. // BUG? On Qt 4.8 and Windows XP Home SP3 32bit - elapsed() always returning value from 0 to 11000
    32. qint64 diff = elapsed_timer.elapsed();
    33. qDebug() << diff;
    34. ui.label->setText(QString::number(diff));
    35. }
    To copy to clipboard, switch view to plain text mode 
    main_window.h:
    Qt Code:
    1. #ifndef MAIN_WINDOW_H
    2. #define MAIN_WINDOW_H
    3.  
    4. #include "ui_main_window.h"
    5. #include <QElapsedTimer>
    6.  
    7. class QTimer;
    8.  
    9. class main_window : public QMainWindow
    10. {
    11. Q_OBJECT
    12. public:
    13. main_window(QWidget * parent = 0);
    14.  
    15. public slots:
    16. void refresh_ui();
    17.  
    18. private:
    19. Ui::main_window ui;
    20. QTimer * refresh_timer;
    21. QElapsedTimer elapsed_timer;
    22. };
    23.  
    24. #endif // MAIN_WINDOW_H
    To copy to clipboard, switch view to plain text mode 
    elapsed_timer_test.pro:
    Qt Code:
    1. QT += core gui
    2.  
    3. TEMPLATE = app
    4.  
    5. HEADERS += main_window.h
    6.  
    7. SOURCES += main.cpp main_window.cpp
    8.  
    9. FORMS += main_window.ui
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QElapsedTimer::elapsed() restarts after ~11000ms on WinXP Home SP3

    Try this code. It works fine on w7 + qt 4.7.2
    Qt Code:
    1. #include <iostream>
    2. #include <QtCore>
    3.  
    4. class Worker: public QObject
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. Worker(): QObject()
    10. {
    11. updateTimer.setInterval(1000);
    12. connect(&updateTimer, SIGNAL(timeout()), this, SLOT(showTimeElapsed()));
    13. }
    14.  
    15. public slots:
    16. void start()
    17. {
    18. elapsedTimer.start();
    19. updateTimer.start();
    20. }
    21.  
    22. private:
    23. QElapsedTimer elapsedTimer;
    24. QTimer updateTimer;
    25.  
    26. private slots:
    27. void showTimeElapsed()
    28. {
    29. std::cout << elapsedTimer.elapsed() << std::endl;
    30. }
    31. };
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35. QCoreApplication a(argc, argv);
    36. Worker worker;
    37. QTimer::singleShot(0, &worker, SLOT(start()));
    38. return a.exec();
    39. }
    40.  
    41. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QElapsedTimer::elapsed() restarts after ~11000ms on WinXP Home SP3


Similar Threads

  1. Elapsed Time on a QLabel. How to do it?
    By GuangZor in forum Newbie
    Replies: 14
    Last Post: 19th April 2017, 20:35
  2. Alternative to QElapsedTimer in old Qt version
    By Asperamanca in forum Qt Programming
    Replies: 3
    Last Post: 27th February 2012, 10:08
  3. Qt Assistant Home button
    By vajindarladdad in forum Newbie
    Replies: 1
    Last Post: 1st October 2009, 13:06
  4. Replies: 6
    Last Post: 25th July 2008, 21:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.