Provide a minimal, complete program that demonstrates the problem. This, for example, shows no such issue:
#include <QtCore>
Q_OBJECT
public:
connect(&timer, SIGNAL(timeout()), SLOT(doSomethingLong()));
timer.setInterval(200);
timer.start();
stopwatch.start();
}
private slots:
void doSomethingLong() {
qDebug() << "Enter" << stopwatch.elapsed();
timer.stop();
// Simulate long runner
qDebug() << " Doing stuff";
t.singleShot(1000, &loop, SLOT(quit()));
loop.exec();
timer.start();
qDebug() << "Leave" << stopwatch.elapsed();
}
};
int main(int argc, char **argv) {
Thingy t;
return app.exec();
}
#include "main.moc"
#include <QtCore>
class Thingy: public QObject {
Q_OBJECT
QTimer timer;
QTime stopwatch;
public:
explicit Thingy(QObject *p = 0): QObject(p) {
connect(&timer, SIGNAL(timeout()), SLOT(doSomethingLong()));
timer.setInterval(200);
timer.start();
stopwatch.start();
}
private slots:
void doSomethingLong() {
qDebug() << "Enter" << stopwatch.elapsed();
timer.stop();
// Simulate long runner
qDebug() << " Doing stuff";
QEventLoop loop;
QTimer t;
t.singleShot(1000, &loop, SLOT(quit()));
loop.exec();
timer.start();
qDebug() << "Leave" << stopwatch.elapsed();
}
};
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
Thingy t;
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
I get 200 milliseconds or 201 milliseconds interval consistently. Total drift over 7 minutes of 23 milliseconds on Linux but more like 400 or 500 milliseconds on Windows.
Bookmarks