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:
#include "main_window.h"
#include <QTimer>
#include <QMessageBox>
#include <QDebug>
main_window
::main_window(QWidget * parent
) :{
ui.setupUi(this);
refresh_timer
= new QTimer(this);
refresh_timer->setInterval(1000);
connect(refresh_timer, SIGNAL(timeout()), SLOT(refresh_ui()));
const int clock_type = QElapsedTimer::clockType();
const bool is_monotonic = QElapsedTimer::isMonotonic();
qDebug() << "QElapsedTimer::clockType() = " << clock_type;
qDebug() << "isMonotonic: " << is_monotonic;
QString("QElapsedTimer::clockType() = %1\n" "isMonotonic: %2")
.
arg(QString::number(clock_type
), is_monotonic ?
"true" : "false"));
elapsed_timer.start();
refresh_timer->start();
}
void main_window::refresh_ui()
{
// BUG? On Qt 4.8 and Windows XP Home SP3 32bit - elapsed() always returning value from 0 to 11000
qint64 diff = elapsed_timer.elapsed();
qDebug() << diff;
ui.
label->setText
(QString::number(diff
));
}
#include "main_window.h"
#include <QTimer>
#include <QMessageBox>
#include <QDebug>
main_window::main_window(QWidget * parent) :
QMainWindow(parent)
{
ui.setupUi(this);
refresh_timer = new QTimer(this);
refresh_timer->setInterval(1000);
connect(refresh_timer, SIGNAL(timeout()), SLOT(refresh_ui()));
const int clock_type = QElapsedTimer::clockType();
const bool is_monotonic = QElapsedTimer::isMonotonic();
qDebug() << "QElapsedTimer::clockType() = " << clock_type;
qDebug() << "isMonotonic: " << is_monotonic;
QMessageBox::information(this, "info",
QString("QElapsedTimer::clockType() = %1\n"
"isMonotonic: %2")
.arg(QString::number(clock_type), is_monotonic ? "true" : "false"));
elapsed_timer.start();
refresh_timer->start();
}
void main_window::refresh_ui()
{
// BUG? On Qt 4.8 and Windows XP Home SP3 32bit - elapsed() always returning value from 0 to 11000
qint64 diff = elapsed_timer.elapsed();
qDebug() << diff;
ui.label->setText(QString::number(diff));
}
To copy to clipboard, switch view to plain text mode
main_window.h:
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include "ui_main_window.h"
#include <QElapsedTimer>
{
Q_OBJECT
public:
public slots:
void refresh_ui();
private:
Ui::main_window ui;
QElapsedTimer elapsed_timer;
};
#endif // MAIN_WINDOW_H
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include "ui_main_window.h"
#include <QElapsedTimer>
class QTimer;
class main_window : public QMainWindow
{
Q_OBJECT
public:
main_window(QWidget * parent = 0);
public slots:
void refresh_ui();
private:
Ui::main_window ui;
QTimer * refresh_timer;
QElapsedTimer elapsed_timer;
};
#endif // MAIN_WINDOW_H
To copy to clipboard, switch view to plain text mode
elapsed_timer_test.pro:
QT += core gui
TEMPLATE = app
HEADERS += main_window.h
SOURCES += main.cpp main_window.cpp
FORMS += main_window.ui
QT += core gui
TEMPLATE = app
HEADERS += main_window.h
SOURCES += main.cpp main_window.cpp
FORMS += main_window.ui
To copy to clipboard, switch view to plain text mode
Bookmarks