PDA

View Full Version : QElapsedTimer::elapsed() restarts after ~11000ms on WinXP Home SP3



lukass
17th February 2012, 18:12
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) :
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));
}

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
elapsed_timer_test.pro:

QT += core gui

TEMPLATE = app

HEADERS += main_window.h

SOURCES += main.cpp main_window.cpp

FORMS += main_window.ui

mentalmushroom
22nd February 2012, 12:52
Try this code. It works fine on w7 + qt 4.7.2


#include <iostream>
#include <QtCore>

class Worker: public QObject
{
Q_OBJECT

public:
Worker(): QObject()
{
updateTimer.setInterval(1000);
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(showTimeElapsed()));
}

public slots:
void start()
{
elapsedTimer.start();
updateTimer.start();
}

private:
QElapsedTimer elapsedTimer;
QTimer updateTimer;

private slots:
void showTimeElapsed()
{
std::cout << elapsedTimer.elapsed() << std::endl;
}
};

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Worker worker;
QTimer::singleShot(0, &worker, SLOT(start()));
return a.exec();
}

#include "main.moc"

lukass
22nd February 2012, 19:56
Try this code. It works fine on w7 + qt 4.7.2
http://troll.me/images/futurama-fry/not-sure-if-trolling-or-just-stupid.jpg

https://bugreports.qt-project.org/browse/QTBUG-24362
https://bugreports.qt-project.org/browse/QTBUG-23150