Convert uses of QTime as a timer to QElapsedTimer

Change-Id: I2297f61efa5adf9ea5194c7f3ff68574cbcf452c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Edward Welbourne 2019-06-12 18:06:23 +02:00 committed by Friedemann Kleint
parent feb06decfe
commit 84e89c1e9e
36 changed files with 124 additions and 110 deletions

View File

@ -132,7 +132,7 @@ void DownloadManager::startNextDownload()
// prepare the output // prepare the output
printf("Downloading %s...\n", url.toEncoded().constData()); printf("Downloading %s...\n", url.toEncoded().constData());
downloadTime.start(); downloadTimer.start();
} }
void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
@ -140,7 +140,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
progressBar.setStatus(bytesReceived, bytesTotal); progressBar.setStatus(bytesReceived, bytesTotal);
// calculate the download speed // calculate the download speed
double speed = bytesReceived * 1000.0 / downloadTime.elapsed(); double speed = bytesReceived * 1000.0 / downloadTimer.elapsed();
QString unit; QString unit;
if (speed < 1024) { if (speed < 1024) {
unit = "bytes/sec"; unit = "bytes/sec";

View File

@ -83,7 +83,7 @@ private:
QQueue<QUrl> downloadQueue; QQueue<QUrl> downloadQueue;
QNetworkReply *currentDownload = nullptr; QNetworkReply *currentDownload = nullptr;
QFile output; QFile output;
QTime downloadTime; QElapsedTimer downloadTimer;
TextProgressBar progressBar; TextProgressBar progressBar;
int downloadedCount = 0; int downloadedCount = 0;

View File

@ -96,8 +96,8 @@ void RateController::transfer()
if (sockets.isEmpty()) if (sockets.isEmpty())
return; return;
int msecs = 1000; qint64 msecs = 1000;
if (!stopWatch.isNull()) if (stopWatch.isValid())
msecs = qMin(msecs, stopWatch.elapsed()); msecs = qMin(msecs, stopWatch.elapsed());
qint64 bytesToWrite = (upLimit * msecs) / 1000; qint64 bytesToWrite = (upLimit * msecs) / 1000;

View File

@ -53,7 +53,7 @@
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
#include <QTime> #include <QElapsedTimer>
class PeerWireClient; class PeerWireClient;
@ -79,7 +79,7 @@ public slots:
void scheduleTransfer(); void scheduleTransfer();
private: private:
QTime stopWatch; QElapsedTimer stopWatch;
QSet<PeerWireClient *> sockets; QSet<PeerWireClient *> sockets;
int upLimit; int upLimit;
int downLimit; int downLimit;

View File

@ -56,7 +56,7 @@
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QVector3D> #include <QVector3D>
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QTime> #include <QElapsedTimer>
#include <QVector> #include <QVector>
#include <QPushButton> #include <QPushButton>
@ -106,7 +106,7 @@ private:
bool m_qtLogo; bool m_qtLogo;
QList<Bubble *> m_bubbles; QList<Bubble *> m_bubbles;
int m_frames; int m_frames;
QTime m_time; QElapsedTimer m_time;
QOpenGLShader *m_vshader1; QOpenGLShader *m_vshader1;
QOpenGLShader *m_fshader1; QOpenGLShader *m_fshader1;
QOpenGLShader *m_vshader2; QOpenGLShader *m_vshader2;

View File

@ -54,7 +54,7 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDir> #include <QDir>
#include <QTime> #include <QElapsedTimer>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
@ -146,19 +146,19 @@ int main(int argc, char** argv)
int singleThreadTime = 0; int singleThreadTime = 0;
{ {
QTime time; QElapsedTimer timer;
time.start(); timer.start();
WordCount total = singleThreadedWordCount(files); WordCount total = singleThreadedWordCount(files);
singleThreadTime = time.elapsed(); singleThreadTime = timer.elapsed();
qDebug() << "single thread" << singleThreadTime; qDebug() << "single thread" << singleThreadTime;
} }
int mapReduceTime = 0; int mapReduceTime = 0;
{ {
QTime time; QElapsedTimer timer;
time.start(); timer.start();
WordCount total = mappedReduced(files, countWords, reduce); WordCount total = mappedReduced(files, countWords, reduce);
mapReduceTime = time.elapsed(); mapReduceTime = timer.elapsed();
qDebug() << "MapReduce" << mapReduceTime; qDebug() << "MapReduce" << mapReduceTime;
} }
qDebug() << "MapReduce speedup x" << ((double)singleThreadTime - (double)mapReduceTime) / (double)mapReduceTime + 1; qDebug() << "MapReduce speedup x" << ((double)singleThreadTime - (double)mapReduceTime) / (double)mapReduceTime + 1;

View File

@ -533,8 +533,6 @@ Scene::Scene(int width, int height, int maxTextureSize)
m_timer->setInterval(20); m_timer->setInterval(20);
connect(m_timer, &QTimer::timeout, this, [this](){ update(); }); connect(m_timer, &QTimer::timeout, this, [this](){ update(); });
m_timer->start(); m_timer->start();
m_time.start();
} }
Scene::~Scene() Scene::~Scene()

View File

@ -220,7 +220,7 @@ private:
void initGL(); void initGL();
QPointF pixelPosToViewPos(const QPointF& p); QPointF pixelPosToViewPos(const QPointF& p);
QTime m_time; QTime m_time; // ### Qt 6: remove (unused)
int m_lastTime; int m_lastTime;
int m_mouseEventTime; int m_mouseEventTime;
int m_distExp; int m_distExp;

View File

@ -54,7 +54,7 @@
#include "arthurwidgets.h" #include "arthurwidgets.h"
#include <QBasicTimer> #include <QBasicTimer>
#include <QDateTime> #include <QElapsedTimer>
#include <QPainterPath> #include <QPainterPath>
class PathDeformRenderer : public ArthurFrame class PathDeformRenderer : public ArthurFrame
@ -103,7 +103,7 @@ private:
QBasicTimer m_repaintTimer; QBasicTimer m_repaintTimer;
// QBasicTimer m_fpsTimer; // QBasicTimer m_fpsTimer;
// int m_fpsCounter; // int m_fpsCounter;
QTime m_repaintTracker; QElapsedTimer m_repaintTracker;
QVector<QPainterPath> m_paths; QVector<QPainterPath> m_paths;
QVector<QPointF> m_advances; QVector<QPointF> m_advances;

View File

@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE
\snippet qelapsedtimer/main.cpp 0 \snippet qelapsedtimer/main.cpp 0
In this example, the timer is started by a call to start() and the In this example, the timer is started by a call to start() and the
elapsed timer is calculated by the elapsed() function. elapsed time is calculated by the elapsed() function.
The time elapsed can also be used to recalculate the time available for The time elapsed can also be used to recalculate the time available for
another operation, after the first one is complete. This is useful when another operation, after the first one is complete. This is useful when

View File

@ -180,7 +180,7 @@
#include "qimagereader.h" #include "qimagereader.h"
#include "qpixmap.h" #include "qpixmap.h"
#include "qrect.h" #include "qrect.h"
#include "qdatetime.h" #include "qelapsedtimer.h"
#include "qtimer.h" #include "qtimer.h"
#include "qpair.h" #include "qpair.h"
#include "qmap.h" #include "qmap.h"

View File

@ -28,6 +28,7 @@
#include <qtconcurrentthreadengine.h> #include <qtconcurrentthreadengine.h>
#include <qexception.h> #include <qexception.h>
#include <QThread> #include <QThread>
#include <QElapsedTimer>
#include <QtTest/QtTest> #include <QtTest/QtTest>
using namespace QtConcurrent; using namespace QtConcurrent;
@ -382,7 +383,7 @@ void tst_QtConcurrentThreadEngine::cancelQueuedSlowUser()
{ {
const int times = 100; const int times = 100;
QTime t; QElapsedTimer t;
t.start(); t.start();
{ {

View File

@ -32,6 +32,7 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QElapsedTimer>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtCore/QTemporaryDir> #include <QtCore/QTemporaryDir>
@ -420,7 +421,7 @@ void tst_QProcess::echoTest()
process.write(input); process.write(input);
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
do { do {
QVERIFY(process.isOpen()); QVERIFY(process.isOpen());
@ -479,7 +480,7 @@ void tst_QProcess::echoTest2()
QVERIFY(spy1.isValid()); QVERIFY(spy1.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
forever { forever {
QTestEventLoop::instance().enterLoop(1); QTestEventLoop::instance().enterLoop(1);
@ -2072,7 +2073,7 @@ void tst_QProcess::fileWriterProcess()
stdinStr += line; stdinStr += line;
} }
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
const QString fileName = m_temporaryDir.path() + QLatin1String("/fileWriterProcess.txt"); const QString fileName = m_temporaryDir.path() + QLatin1String("/fileWriterProcess.txt");
const QString binary = QDir::currentPath() + QLatin1String("/fileWriterProcess/fileWriterProcess"); const QString binary = QDir::currentPath() + QLatin1String("/fileWriterProcess/fileWriterProcess");

View File

@ -34,6 +34,7 @@
#include <QSharedMemory> #include <QSharedMemory>
#include <QTest> #include <QTest>
#include <QThread> #include <QThread>
#include <QElapsedTimer>
#define EXISTING_SHARE "existing" #define EXISTING_SHARE "existing"
#define EXISTING_SIZE 1024 #define EXISTING_SIZE 1024
@ -645,7 +646,7 @@ public:
char *memory = (char*)producer.data(); char *memory = (char*)producer.data();
memory[1] = '0'; memory[1] = '0';
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
int i = 0; int i = 0;
while (i < 5 && timer.elapsed() < 5000) { while (i < 5 && timer.elapsed() < 5000) {

View File

@ -38,6 +38,7 @@
#include <qtimer.h> #include <qtimer.h>
#include <qthread.h> #include <qthread.h>
#include <qelapsedtimer.h>
#if defined Q_OS_UNIX #if defined Q_OS_UNIX
#include <unistd.h> #include <unistd.h>
@ -526,7 +527,7 @@ public:
QBasicTimer m_timer; QBasicTimer m_timer;
int m_interval; int m_interval;
QTime m_startedTime; QElapsedTimer m_elapsedTimer;
QEventLoop eventLoop; QEventLoop eventLoop;
inline RestartedTimerFiresTooSoonObject() inline RestartedTimerFiresTooSoonObject()
@ -538,7 +539,7 @@ public:
static int interval = 1000; static int interval = 1000;
m_interval = interval; m_interval = interval;
m_startedTime.start(); m_elapsedTimer.start();
m_timer.start(interval, this); m_timer.start(interval, this);
// alternate between single-shot and 1 sec // alternate between single-shot and 1 sec
@ -552,7 +553,7 @@ public:
m_timer.stop(); m_timer.stop();
int elapsed = m_startedTime.elapsed(); int elapsed = m_elapsedTimer.elapsed();
if (elapsed < m_interval / 2) { if (elapsed < m_interval / 2) {
// severely too early! // severely too early!
@ -590,10 +591,10 @@ public:
public slots: public slots:
void longLastingSlot() void longLastingSlot()
{ {
// Don't use timers for this, because we are testing them. // Don't use QTimer for this, because we are testing it.
QTime time; QElapsedTimer control;
time.start(); control.start();
while (time.elapsed() < 200) { while (control.elapsed() < 200) {
for (int c = 0; c < 100000; c++) {} // Mindless looping. for (int c = 0; c < 100000; c++) {} // Mindless looping.
} }
if (++count >= 2) { if (++count >= 2) {

View File

@ -35,6 +35,7 @@
#include <QBuffer> #include <QBuffer>
#include <QByteArray> #include <QByteArray>
#include <QDebug> #include <QDebug>
#include <QElapsedTimer>
#include <QFile> #include <QFile>
#include <QTcpSocket> #include <QTcpSocket>
#include <QTemporaryDir> #include <QTemporaryDir>
@ -996,7 +997,7 @@ struct CompareIndicesForArray
void tst_QTextStream::performance() void tst_QTextStream::performance()
{ {
// Phase #1 - test speed of reading a huge text file with QFile. // Phase #1 - test speed of reading a huge text file with QFile.
QTime stopWatch; QElapsedTimer stopWatch;
const int N = 3; const int N = 3;
const char * readMethods[N] = { const char * readMethods[N] = {

View File

@ -31,6 +31,7 @@
#include <QAtomicInt> #include <QAtomicInt>
#include <QCoreApplication> #include <QCoreApplication>
#include <QElapsedTimer>
#include <limits.h> #include <limits.h>
@ -851,7 +852,7 @@ void tst_QAtomicInt::operators()
void tst_QAtomicInt::testAndSet_loop() void tst_QAtomicInt::testAndSet_loop()
{ {
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
int iterations = 10000000; int iterations = 10000000;

View File

@ -27,6 +27,7 @@
****************************************************************************/ ****************************************************************************/
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QElapsedTimer>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QtConcurrent> #include <QtConcurrent>
@ -878,7 +879,7 @@ void tst_QFutureWatcher::incrementalFilterResults()
void tst_QFutureWatcher::qfutureSynchronizer() void tst_QFutureWatcher::qfutureSynchronizer()
{ {
int taskCount = 1000; int taskCount = 1000;
QTime t; QElapsedTimer t;
t.start(); t.start();
{ {

View File

@ -29,6 +29,7 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qcoreapplication.h> #include <qcoreapplication.h>
#include <qreadwritelock.h> #include <qreadwritelock.h>
#include <qelapsedtimer.h>
#include <qmutex.h> #include <qmutex.h>
#include <qthread.h> #include <qthread.h>
#include <qwaitcondition.h> #include <qwaitcondition.h>
@ -237,7 +238,7 @@ void tst_QReadWriteLock::tryReadLock()
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
QVERIFY(!readWriteLock.tryLockForRead(1000)); QVERIFY(!readWriteLock.tryLockForRead(1000));
QVERIFY(timer.elapsed() >= 1000); QVERIFY(timer.elapsed() >= 1000);
@ -500,7 +501,7 @@ public:
int holdTime; int holdTime;
int waitTime; int waitTime;
bool print; bool print;
QTime t; QElapsedTimer t;
inline ReadLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) inline ReadLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false)
:testRwlock(l) :testRwlock(l)
,runTime(runTime) ,runTime(runTime)
@ -536,7 +537,7 @@ public:
int holdTime; int holdTime;
int waitTime; int waitTime;
bool print; bool print;
QTime t; QElapsedTimer t;
inline WriteLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) inline WriteLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false)
:testRwlock(l) :testRwlock(l)
,runTime(runTime) ,runTime(runTime)
@ -574,7 +575,7 @@ public:
int runTime; int runTime;
int waitTime; int waitTime;
int maxval; int maxval;
QTime t; QElapsedTimer t;
inline WriteLockCountThread(QReadWriteLock &l, int runTime, int waitTime, int maxval) inline WriteLockCountThread(QReadWriteLock &l, int runTime, int waitTime, int maxval)
:testRwlock(l) :testRwlock(l)
,runTime(runTime) ,runTime(runTime)
@ -615,7 +616,7 @@ public:
QReadWriteLock &testRwlock; QReadWriteLock &testRwlock;
int runTime; int runTime;
int waitTime; int waitTime;
QTime t; QElapsedTimer t;
inline ReadLockCountThread(QReadWriteLock &l, int runTime, int waitTime) inline ReadLockCountThread(QReadWriteLock &l, int runTime, int waitTime)
:testRwlock(l) :testRwlock(l)
,runTime(runTime) ,runTime(runTime)
@ -873,7 +874,7 @@ void tst_QReadWriteLock::deleteOnUnlock()
DeleteOnUnlockThread thread2(&lock, &startup, &waitMutex); DeleteOnUnlockThread thread2(&lock, &startup, &waitMutex);
QTime t; QElapsedTimer t;
t.start(); t.start();
while(t.elapsed() < 4000) { while(t.elapsed() < 4000) {
lock = new QReadWriteLock(); lock = new QReadWriteLock();
@ -899,7 +900,7 @@ void tst_QReadWriteLock::uncontendedLocks()
uint count=0; uint count=0;
int millisecs=1000; int millisecs=1000;
{ {
QTime t; QElapsedTimer t;
t.start(); t.start();
while(t.elapsed() <millisecs) while(t.elapsed() <millisecs)
{ {
@ -908,7 +909,7 @@ void tst_QReadWriteLock::uncontendedLocks()
} }
{ {
QReadWriteLock rwlock; QReadWriteLock rwlock;
QTime t; QElapsedTimer t;
t.start(); t.start();
while(t.elapsed() <millisecs) while(t.elapsed() <millisecs)
{ {
@ -919,7 +920,7 @@ void tst_QReadWriteLock::uncontendedLocks()
} }
{ {
QReadWriteLock rwlock; QReadWriteLock rwlock;
QTime t; QElapsedTimer t;
t.start(); t.start();
while(t.elapsed() <millisecs) while(t.elapsed() <millisecs)
{ {

View File

@ -29,7 +29,7 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qcoreapplication.h> #include <qcoreapplication.h>
#include <qdatetime.h> #include <qelapsedtimer.h>
#include <qmutex.h> #include <qmutex.h>
#include <qthread.h> #include <qthread.h>
#include <qtimer.h> #include <qtimer.h>
@ -244,8 +244,8 @@ public:
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
elapsed = 0; elapsed = 0;
QTime time; QElapsedTimer timer;
time.start(); timer.start();
switch (sleepType) { switch (sleepType) {
case Second: case Second:
sleep(interval); sleep(interval);
@ -257,7 +257,7 @@ public:
usleep(interval); usleep(interval);
break; break;
} }
elapsed = time.elapsed(); elapsed = timer.elapsed();
cond.wakeOne(); cond.wakeOne();
} }
@ -601,8 +601,7 @@ void tst_QThread::msleep()
thread.interval = 120; thread.interval = 120;
thread.start(); thread.start();
QVERIFY(thread.wait(five_minutes)); QVERIFY(thread.wait(five_minutes));
#if defined (Q_OS_WIN) #if defined (Q_OS_WIN) // May no longer be needed
// Since the resolution of QTime is so coarse...
QVERIFY(thread.elapsed >= 100); QVERIFY(thread.elapsed >= 100);
#else #else
QVERIFY(thread.elapsed >= 120); QVERIFY(thread.elapsed >= 120);
@ -616,8 +615,7 @@ void tst_QThread::usleep()
thread.interval = 120000; thread.interval = 120000;
thread.start(); thread.start();
QVERIFY(thread.wait(five_minutes)); QVERIFY(thread.wait(five_minutes));
#if defined (Q_OS_WIN) #if defined (Q_OS_WIN) // May no longer be needed
// Since the resolution of QTime is so coarse...
QVERIFY(thread.elapsed >= 100); QVERIFY(thread.elapsed >= 100);
#else #else
QVERIFY(thread.elapsed >= 120); QVERIFY(thread.elapsed >= 120);
@ -948,9 +946,9 @@ void tst_QThread::stressTest()
if (EmulationDetector::isRunningArmOnX86()) if (EmulationDetector::isRunningArmOnX86())
QSKIP("Qemu uses too much memory for each thread. Test would run out of memory."); QSKIP("Qemu uses too much memory for each thread. Test would run out of memory.");
QTime t; QElapsedTimer timer;
t.start(); timer.start();
while (t.elapsed() < one_minute) { while (timer.elapsed() < one_minute) {
Current_Thread t; Current_Thread t;
t.start(); t.start();
t.wait(one_minute); t.wait(one_minute);

View File

@ -27,7 +27,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qdatetime.h> #include <qelapsedtimer.h>
#include <qthreadpool.h> #include <qthreadpool.h>
#include <qstring.h> #include <qstring.h>
#include <qmutex.h> #include <qmutex.h>
@ -882,7 +882,7 @@ void tst_QThreadPool::priorityStart()
void tst_QThreadPool::waitForDone() void tst_QThreadPool::waitForDone()
{ {
QTime total, pass; QElapsedTimer total, pass;
total.start(); total.start();
QThreadPool threadPool; QThreadPool threadPool;
@ -1113,7 +1113,7 @@ void tst_QThreadPool::tryTake()
void tst_QThreadPool::destroyingWaitsForTasksToFinish() void tst_QThreadPool::destroyingWaitsForTasksToFinish()
{ {
QTime total, pass; QElapsedTimer total, pass;
total.start(); total.start();
while (total.elapsed() < 10000) { while (total.elapsed() < 10000) {
@ -1204,7 +1204,7 @@ void tst_QThreadPool::stressTest()
} }
}; };
QTime total; QElapsedTimer total;
total.start(); total.start();
while (total.elapsed() < 30000) { while (total.elapsed() < 30000) {
Task t; Task t;

View File

@ -43,6 +43,7 @@
#include <QtNetwork/private/qnetworksession_p.h> #include <QtNetwork/private/qnetworksession_p.h>
#include <QTcpServer> #include <QTcpServer>
#include <QHostInfo> #include <QHostInfo>
#include <QElapsedTimer>
#include <QTcpSocket> #include <QTcpSocket>
#include "../../../network-settings.h" #include "../../../network-settings.h"
@ -2160,7 +2161,7 @@ void tst_QFtp::qtbug7359Crash()
QFtp ftp; QFtp ftp;
ftp.connectToHost("127.0.0.1"); ftp.connectToHost("127.0.0.1");
QTime t; QElapsedTimer t;
int elapsed; int elapsed;
t.start(); t.start();

View File

@ -32,6 +32,7 @@
#include <QtCore/QDataStream> #include <QtCore/QDataStream>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <QtCore/QEventLoop> #include <QtCore/QEventLoop>
#include <QtCore/QElapsedTimer>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QRandomGenerator> #include <QtCore/QRandomGenerator>
#include <QtCore/QRegularExpression> #include <QtCore/QRegularExpression>
@ -1149,7 +1150,7 @@ protected:
} }
// now write in "blocking mode", this is where the rate measuring starts // now write in "blocking mode", this is where the rate measuring starts
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
//const qint64 writtenBefore = dataIndex; //const qint64 writtenBefore = dataIndex;
//qint64 measuredTotalBytes = wantedSize - writtenBefore; //qint64 measuredTotalBytes = wantedSize - writtenBefore;
@ -1248,7 +1249,7 @@ protected:
} }
qint64 bytesRead = 0; qint64 bytesRead = 0;
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
do { do {
if (device->bytesAvailable() == 0) { if (device->bytesAvailable() == 0) {
@ -5153,8 +5154,8 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
const int rate = 200; // in kB per sec const int rate = 200; // in kB per sec
RateControlledReader reader(server, reply.data(), rate, bufferSize); RateControlledReader reader(server, reply.data(), rate, bufferSize);
QTime loopTime; QElapsedTimer loopTimer;
loopTime.start(); loopTimer.start();
const int result = waitForFinish(reply); const int result = waitForFinish(reply);
if (notEnoughDataForFastSender) { if (notEnoughDataForFastSender) {
@ -5164,7 +5165,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
QVERIFY2(result == Success, msgWaitForFinished(reply)); QVERIFY2(result == Success, msgWaitForFinished(reply));
const int elapsedTime = loopTime.elapsed(); const int elapsedTime = loopTimer.elapsed();
server.wait(); server.wait();
reader.wrapUp(); reader.wrapUp();
@ -5450,12 +5451,12 @@ void tst_QNetworkReply::rateControl()
RateControlledReader reader(sender, reply.data(), rate, 20); RateControlledReader reader(sender, reply.data(), rate, 20);
// this test is designed to run for 25 seconds at most // this test is designed to run for 25 seconds at most
QTime loopTime; QElapsedTimer loopTimer;
loopTime.start(); loopTimer.start();
QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply)); QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply));
int elapsedTime = loopTime.elapsed(); int elapsedTime = loopTimer.elapsed();
if (!errorSpy.isEmpty()) { if (!errorSpy.isEmpty()) {
qDebug() << "ERROR!" << errorSpy[0][0] << reply->errorString(); qDebug() << "ERROR!" << errorSpy[0][0] << reply->errorString();
@ -6125,8 +6126,8 @@ void tst_QNetworkReply::httpConnectionCount()
} }
int pendingConnectionCount = 0; int pendingConnectionCount = 0;
QTime time; QElapsedTimer timer;
time.start(); timer.start();
while(pendingConnectionCount <= 20) { while(pendingConnectionCount <= 20) {
QTestEventLoop::instance().enterLoop(1); QTestEventLoop::instance().enterLoop(1);
@ -6138,7 +6139,7 @@ void tst_QNetworkReply::httpConnectionCount()
} }
// at max. wait 10 sec // at max. wait 10 sec
if (time.elapsed() > 10000) if (timer.elapsed() > 10000)
break; break;
} }

View File

@ -32,7 +32,7 @@
#include <qcoreapplication.h> #include <qcoreapplication.h>
#include <qdatastream.h> #include <qdatastream.h>
#include <qhostaddress.h> #include <qhostaddress.h>
#include <qdatetime.h> #include <qelapsedtimer.h>
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
#include <unistd.h> #include <unistd.h>
@ -403,7 +403,7 @@ void tst_PlatformSocketEngine::udpLoopbackPerformance()
QHostAddress localhost = QHostAddress::LocalHost; QHostAddress localhost = QHostAddress::LocalHost;
qlonglong readBytes = 0; qlonglong readBytes = 0;
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
while (timer.elapsed() < 5000) { while (timer.elapsed() < 5000) {
udpSocket2.write(message1.data(), message1.size()); udpSocket2.write(message1.data(), message1.size());
@ -462,7 +462,7 @@ void tst_PlatformSocketEngine::tcpLoopbackPerformance()
QByteArray message1(messageSize, '@'); QByteArray message1(messageSize, '@');
QByteArray answer(messageSize, '@'); QByteArray answer(messageSize, '@');
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
qlonglong readBytes = 0; qlonglong readBytes = 0;
while (timer.elapsed() < 5000) { while (timer.elapsed() < 5000) {

View File

@ -38,6 +38,7 @@
#include <qhostaddress.h> #include <qhostaddress.h>
#include <qtcpsocket.h> #include <qtcpsocket.h>
#include <qdebug.h> #include <qdebug.h>
#include <qelapsedtimer.h>
#include <qtcpserver.h> #include <qtcpserver.h>
#include "../../../network-settings.h" #include "../../../network-settings.h"
@ -397,7 +398,7 @@ void tst_QHttpSocketEngine::tcpLoopbackPerformance()
QByteArray message1(messageSize, '@'); QByteArray message1(messageSize, '@');
QByteArray answer(messageSize, '@'); QByteArray answer(messageSize, '@');
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
qlonglong readBytes = 0; qlonglong readBytes = 0;
while (timer.elapsed() < 30000) { while (timer.elapsed() < 30000) {
@ -629,7 +630,7 @@ void tst_QHttpSocketEngine::downloadBigFile()
bytesAvailable = 0; bytesAvailable = 0;
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
QTestEventLoop::instance().enterLoop(60); QTestEventLoop::instance().enterLoop(60);

View File

@ -32,6 +32,7 @@
#include <qtextstream.h> #include <qtextstream.h>
#include <qdatastream.h> #include <qdatastream.h>
#include <qelapsedtimer.h>
#include <QtNetwork/qlocalsocket.h> #include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h> #include <QtNetwork/qlocalserver.h>
@ -1031,7 +1032,7 @@ void tst_QLocalSocket::waitForDisconnect()
QLocalSocket *serverSocket = server.nextPendingConnection(); QLocalSocket *serverSocket = server.nextPendingConnection();
QVERIFY(serverSocket); QVERIFY(serverSocket);
socket.disconnectFromServer(); socket.disconnectFromServer();
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
QVERIFY(serverSocket->waitForDisconnected(3000)); QVERIFY(serverSocket->waitForDisconnected(3000));
QVERIFY(timer.elapsed() < 2000); QVERIFY(timer.elapsed() < 2000);

View File

@ -66,7 +66,7 @@
#endif #endif
#include <QTextStream> #include <QTextStream>
#include <QThread> #include <QThread>
#include <QTime> #include <QElapsedTimer>
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
// RVCT compiles also unused inline methods // RVCT compiles also unused inline methods
@ -237,7 +237,6 @@ private:
qint64 bytesAvailable; qint64 bytesAvailable;
qint64 expectedLength; qint64 expectedLength;
bool readingBody; bool readingBody;
QTime timer;
QByteArray expectedReplyIMAP_cached; QByteArray expectedReplyIMAP_cached;
@ -1518,7 +1517,7 @@ void tst_QTcpSocket::downloadBigFile()
expectedLength = 0; expectedLength = 0;
readingBody = false; readingBody = false;
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
enterLoop(600); enterLoop(600);
@ -2482,7 +2481,7 @@ void tst_QTcpSocket::suddenRemoteDisconnect()
QEventLoop loop; QEventLoop loop;
connect(&serverProcess, SIGNAL(finished(int)), &loop, SLOT(quit())); connect(&serverProcess, SIGNAL(finished(int)), &loop, SLOT(quit()));
connect(&clientProcess, SIGNAL(finished(int)), &loop, SLOT(quit())); connect(&clientProcess, SIGNAL(finished(int)), &loop, SLOT(quit()));
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
QTimer::singleShot(20000, &loop, SLOT(quit())); QTimer::singleShot(20000, &loop, SLOT(quit()));
@ -2522,7 +2521,7 @@ void tst_QTcpSocket::connectToMultiIP()
// rationale: this domain resolves to 3 A-records, 2 of them are // rationale: this domain resolves to 3 A-records, 2 of them are
// invalid. QTcpSocket should never spend more than 30 seconds per IP, and // invalid. QTcpSocket should never spend more than 30 seconds per IP, and
// 30s*2 = 60s. // 30s*2 = 60s.
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
socket->connectToHost("multi.dev.qt-project.org", 80); socket->connectToHost("multi.dev.qt-project.org", 80);
QVERIFY(socket->waitForConnected(60500)); QVERIFY(socket->waitForConnected(60500));
@ -2714,7 +2713,7 @@ void tst_QTcpSocket::taskQtBug5799ConnectionErrorWaitForConnected()
QTcpSocket socket; QTcpSocket socket;
socket.connectToHost(QtNetworkSettings::httpServerName(), 12346); socket.connectToHost(QtNetworkSettings::httpServerName(), 12346);
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
socket.waitForConnected(10000); socket.waitForConnected(10000);
QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong");

View File

@ -40,6 +40,7 @@
#include <qhostinfo.h> #include <qhostinfo.h>
#include <qtcpsocket.h> #include <qtcpsocket.h>
#include <qmap.h> #include <qmap.h>
#include <qelapsedtimer.h>
#include <qnetworkdatagram.h> #include <qnetworkdatagram.h>
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QNetworkInterface> #include <QNetworkInterface>
@ -922,7 +923,7 @@ void tst_QUdpSocket::performance()
client.connectToHost(serverAddress, server.localPort()); client.connectToHost(serverAddress, server.localPort());
QVERIFY(client.waitForConnected(10000)); QVERIFY(client.waitForConnected(10000));
QTime stopWatch; QElapsedTimer stopWatch;
stopWatch.start(); stopWatch.start();
qint64 nbytes = 0; qint64 nbytes = 0;

View File

@ -29,6 +29,7 @@
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/qthread.h> #include <QtCore/qthread.h>
#include <QtCore/qelapsedtimer.h>
#include <QtNetwork/qhostaddress.h> #include <QtNetwork/qhostaddress.h>
#include <QtNetwork/qhostinfo.h> #include <QtNetwork/qhostinfo.h>
#include <QtNetwork/qnetworkproxy.h> #include <QtNetwork/qnetworkproxy.h>
@ -1989,7 +1990,7 @@ public slots:
QTestEventLoop::instance().exitLoop(); QTestEventLoop::instance().exitLoop();
} }
void waitSomeMore(QSslSocket *socket) { void waitSomeMore(QSslSocket *socket) {
QTime t; QElapsedTimer t;
t.start(); t.start();
while (!socket->encryptedBytesAvailable()) { while (!socket->encryptedBytesAvailable()) {
QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 250); QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 250);

View File

@ -33,6 +33,7 @@
#include <qpa/qplatformintegration.h> #include <qpa/qplatformintegration.h>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtOpenGL/QtOpenGL> #include <QtOpenGL/QtOpenGL>
#include <qelapsedtimer.h>
#include "tst_qglthreads.h" #include "tst_qglthreads.h"
#ifndef QT_OPENGL_ES_2 #ifndef QT_OPENGL_ES_2
@ -74,9 +75,9 @@ public:
} }
void run() { void run() {
QTime time; QElapsedTimer timer;
time.start(); timer.start();
while (time.elapsed() < RUNNING_TIME) { while (timer.elapsed() < RUNNING_TIME) {
lock(); lock();
waitForReadyToSwap(); waitForReadyToSwap();
@ -291,11 +292,11 @@ public:
} }
void run() { void run() {
QTime time; QElapsedTimer timer;
time.start(); timer.start();
failure = false; failure = false;
while (time.elapsed() < RUNNING_TIME && !failure) { while (timer.elapsed() < RUNNING_TIME && !failure) {
m_widget->makeCurrent(); m_widget->makeCurrent();
@ -466,13 +467,13 @@ public:
public slots: public slots:
void draw() { void draw() {
bool beginFailed = false; bool beginFailed = false;
QTime time; QElapsedTimer timer;
time.start(); timer.start();
int rotAngle = 10; int rotAngle = 10;
device->prepareDevice(); device->prepareDevice();
QPaintDevice *paintDevice = device->realPaintDevice(); QPaintDevice *paintDevice = device->realPaintDevice();
QSize s(paintDevice->width(), paintDevice->height()); QSize s(paintDevice->width(), paintDevice->height());
while (time.elapsed() < RUNNING_TIME) { while (timer.elapsed() < RUNNING_TIME) {
QPainter p; QPainter p;
if (!p.begin(paintDevice)) { if (!p.begin(paintDevice)) {
beginFailed = true; beginFailed = true;

View File

@ -29,6 +29,7 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QtNetwork/QtNetwork> #include <QtNetwork/QtNetwork>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QElapsedTimer>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QRandomGenerator> #include <QtCore/QRandomGenerator>
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
@ -195,7 +196,7 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000)
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket); QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
#endif #endif
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
int t = timeout; int t = timeout;
forever { forever {
@ -421,7 +422,7 @@ void tst_NetworkSelfTest::serverReachability()
QTcpSocket socket; QTcpSocket socket;
socket.connectToHost(QtNetworkSettings::serverName(), 12346); socket.connectToHost(QtNetworkSettings::serverName(), 12346);
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
socket.waitForConnected(10000); socket.waitForConnected(10000);
QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong");

View File

@ -85,7 +85,7 @@ class RaceThread : public QThread
{ {
Q_OBJECT Q_OBJECT
RaceObject *object; RaceObject *object;
QTime stopWatch; QElapsedTimer stopWatch;
public: public:
RaceThread() RaceThread()

View File

@ -32,6 +32,7 @@
#include <QtSql> #include <QtSql>
#include <QtSql/private/qsqltablemodel_p.h> #include <QtSql/private/qsqltablemodel_p.h>
#include <QThread> #include <QThread>
#include <QElapsedTimer>
const QString test(qTableName("test", __FILE__, QSqlDatabase())), const QString test(qTableName("test", __FILE__, QSqlDatabase())),
test2(qTableName("test2", __FILE__, QSqlDatabase())), test2(qTableName("test2", __FILE__, QSqlDatabase())),
@ -1804,12 +1805,12 @@ void tst_QSqlTableModel::sqlite_bigTable()
QSqlQuery q(db); QSqlQuery q(db);
QVERIFY_SQL( q, exec("create table "+bigtable+"(id int primary key, name varchar)")); QVERIFY_SQL( q, exec("create table "+bigtable+"(id int primary key, name varchar)"));
QVERIFY_SQL( q, prepare("insert into "+bigtable+"(id, name) values (?, ?)")); QVERIFY_SQL( q, prepare("insert into "+bigtable+"(id, name) values (?, ?)"));
QTime startTime; QElapsedTimer timing;
startTime.start(); timing.start();
for (int i = 0; i < 10000; ++i) { for (int i = 0; i < 10000; ++i) {
q.addBindValue(i); q.addBindValue(i);
q.addBindValue(QString::number(i)); q.addBindValue(QString::number(i));
if(i%1000 == 0 && startTime.elapsed() > 5000) if (i % 1000 == 0 && timing.elapsed() > 5000)
qDebug() << i << "records written"; qDebug() << i << "records written";
QVERIFY_SQL( q, exec()); QVERIFY_SQL( q, exec());
} }

View File

@ -28,6 +28,7 @@
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QElapsedTimer>
#include <QtTest/QtTest> #include <QtTest/QtTest>
class tst_Sleep: public QObject class tst_Sleep: public QObject
@ -41,7 +42,7 @@ private slots:
void tst_Sleep::sleep() void tst_Sleep::sleep()
{ {
QTime t; QElapsedTimer t;
t.start(); t.start();
QTest::qSleep(100); QTest::qSleep(100);

View File

@ -33,7 +33,7 @@
#include <QSlider> #include <QSlider>
#include <QStyle> #include <QStyle>
#include <QStyleOption> #include <QStyleOption>
#include <QTime> #include <QElapsedTimer>
#include <QDebug> #include <QDebug>
#include <QtTest/private/qtesthelpers_p.h> #include <QtTest/private/qtesthelpers_p.h>
@ -91,7 +91,7 @@ private slots:
void connectedSliders(); void connectedSliders();
private: private:
void waitUntilTimeElapsed(const QTime& t, int ms); void waitUntilTimeElapsed(const QElapsedTimer &t, int ms);
QWidget *topLevel; QWidget *topLevel;
Slider *slider; Slider *slider;
@ -2053,11 +2053,11 @@ void tst_QAbstractSlider::setValue()
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
} }
void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms) void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer &t, int ms)
{ {
const int eps = 80; const int eps = 80;
while (t.elapsed() < ms + eps) while (t.elapsed() < ms + eps)
QTest::qWait(qMax(ms - t.elapsed() + eps, 25)); QTest::qWait(qMax(int(ms - t.elapsed() + eps), 25));
} }
void tst_QAbstractSlider::setRepeatAction() void tst_QAbstractSlider::setRepeatAction()
@ -2073,7 +2073,7 @@ void tst_QAbstractSlider::setRepeatAction()
QCOMPARE(spy.count(), 0); QCOMPARE(spy.count(), 0);
QCOMPARE(slider->value(), 55); QCOMPARE(slider->value(), 55);
QTime t; QElapsedTimer t;
t.start(); t.start();
QTest::qWait(300); QTest::qWait(300);
QCOMPARE(spy.count(), 0); QCOMPARE(spy.count(), 0);

View File

@ -34,6 +34,7 @@
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QTimer> #include <QTimer>
#include <QElapsedTimer>
#include <QtDebug> #include <QtDebug>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QXmlDefaultHandler> #include <QXmlDefaultHandler>
@ -259,7 +260,7 @@ public:
// Delibrately wait a maximum of 10 seconds for the sake // Delibrately wait a maximum of 10 seconds for the sake
// of the test, so it doesn't unduly hang // of the test, so it doesn't unduly hang
const int waitTime = qMax(10000, msecs); const int waitTime = qMax(10000, msecs);
QTime t; QElapsedTimer t;
t.start(); t.start();
while (t.elapsed() < waitTime) { while (t.elapsed() < waitTime) {
QCoreApplication::processEvents(); QCoreApplication::processEvents();