From 84e89c1e9e00d4fab576b876cfa80e92b5602982 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 12 Jun 2019 18:06:23 +0200 Subject: Convert uses of QTime as a timer to QElapsedTimer Change-Id: I2297f61efa5adf9ea5194c7f3ff68574cbcf452c Reviewed-by: Friedemann Kleint --- examples/network/downloadmanager/downloadmanager.cpp | 4 ++-- examples/network/downloadmanager/downloadmanager.h | 2 +- examples/network/torrent/ratecontroller.cpp | 4 ++-- examples/network/torrent/ratecontroller.h | 4 ++-- examples/opengl/qopenglwidget/glwidget.h | 4 ++-- examples/qtconcurrent/wordcount/main.cpp | 14 +++++++------- examples/widgets/graphicsview/boxes/scene.cpp | 2 -- examples/widgets/graphicsview/boxes/scene.h | 2 +- examples/widgets/painting/deform/pathdeform.h | 4 ++-- 9 files changed, 19 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/network/downloadmanager/downloadmanager.cpp b/examples/network/downloadmanager/downloadmanager.cpp index e820b4ff70..9e0c03c6af 100644 --- a/examples/network/downloadmanager/downloadmanager.cpp +++ b/examples/network/downloadmanager/downloadmanager.cpp @@ -132,7 +132,7 @@ void DownloadManager::startNextDownload() // prepare the output printf("Downloading %s...\n", url.toEncoded().constData()); - downloadTime.start(); + downloadTimer.start(); } void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) @@ -140,7 +140,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) progressBar.setStatus(bytesReceived, bytesTotal); // calculate the download speed - double speed = bytesReceived * 1000.0 / downloadTime.elapsed(); + double speed = bytesReceived * 1000.0 / downloadTimer.elapsed(); QString unit; if (speed < 1024) { unit = "bytes/sec"; diff --git a/examples/network/downloadmanager/downloadmanager.h b/examples/network/downloadmanager/downloadmanager.h index 4bc6351ff9..818a774f1f 100644 --- a/examples/network/downloadmanager/downloadmanager.h +++ b/examples/network/downloadmanager/downloadmanager.h @@ -83,7 +83,7 @@ private: QQueue downloadQueue; QNetworkReply *currentDownload = nullptr; QFile output; - QTime downloadTime; + QElapsedTimer downloadTimer; TextProgressBar progressBar; int downloadedCount = 0; diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp index 87c65096b6..96474806f5 100644 --- a/examples/network/torrent/ratecontroller.cpp +++ b/examples/network/torrent/ratecontroller.cpp @@ -96,8 +96,8 @@ void RateController::transfer() if (sockets.isEmpty()) return; - int msecs = 1000; - if (!stopWatch.isNull()) + qint64 msecs = 1000; + if (stopWatch.isValid()) msecs = qMin(msecs, stopWatch.elapsed()); qint64 bytesToWrite = (upLimit * msecs) / 1000; diff --git a/examples/network/torrent/ratecontroller.h b/examples/network/torrent/ratecontroller.h index a4aa596ce1..f8bff0cc36 100644 --- a/examples/network/torrent/ratecontroller.h +++ b/examples/network/torrent/ratecontroller.h @@ -53,7 +53,7 @@ #include #include -#include +#include class PeerWireClient; @@ -79,7 +79,7 @@ public slots: void scheduleTransfer(); private: - QTime stopWatch; + QElapsedTimer stopWatch; QSet sockets; int upLimit; int downLimit; diff --git a/examples/opengl/qopenglwidget/glwidget.h b/examples/opengl/qopenglwidget/glwidget.h index de7805a907..0ad2581cb8 100644 --- a/examples/opengl/qopenglwidget/glwidget.h +++ b/examples/opengl/qopenglwidget/glwidget.h @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include @@ -106,7 +106,7 @@ private: bool m_qtLogo; QList m_bubbles; int m_frames; - QTime m_time; + QElapsedTimer m_time; QOpenGLShader *m_vshader1; QOpenGLShader *m_fshader1; QOpenGLShader *m_vshader2; diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp index 32cb4d0e08..ae8542a761 100644 --- a/examples/qtconcurrent/wordcount/main.cpp +++ b/examples/qtconcurrent/wordcount/main.cpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include @@ -146,19 +146,19 @@ int main(int argc, char** argv) int singleThreadTime = 0; { - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); WordCount total = singleThreadedWordCount(files); - singleThreadTime = time.elapsed(); + singleThreadTime = timer.elapsed(); qDebug() << "single thread" << singleThreadTime; } int mapReduceTime = 0; { - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); WordCount total = mappedReduced(files, countWords, reduce); - mapReduceTime = time.elapsed(); + mapReduceTime = timer.elapsed(); qDebug() << "MapReduce" << mapReduceTime; } qDebug() << "MapReduce speedup x" << ((double)singleThreadTime - (double)mapReduceTime) / (double)mapReduceTime + 1; diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 7f62ac894b..d51124aed7 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -533,8 +533,6 @@ Scene::Scene(int width, int height, int maxTextureSize) m_timer->setInterval(20); connect(m_timer, &QTimer::timeout, this, [this](){ update(); }); m_timer->start(); - - m_time.start(); } Scene::~Scene() diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h index ccb6f368cd..ffff01358f 100644 --- a/examples/widgets/graphicsview/boxes/scene.h +++ b/examples/widgets/graphicsview/boxes/scene.h @@ -220,7 +220,7 @@ private: void initGL(); QPointF pixelPosToViewPos(const QPointF& p); - QTime m_time; + QTime m_time; // ### Qt 6: remove (unused) int m_lastTime; int m_mouseEventTime; int m_distExp; diff --git a/examples/widgets/painting/deform/pathdeform.h b/examples/widgets/painting/deform/pathdeform.h index b7c7386e2a..af869badc9 100644 --- a/examples/widgets/painting/deform/pathdeform.h +++ b/examples/widgets/painting/deform/pathdeform.h @@ -54,7 +54,7 @@ #include "arthurwidgets.h" #include -#include +#include #include class PathDeformRenderer : public ArthurFrame @@ -103,7 +103,7 @@ private: QBasicTimer m_repaintTimer; // QBasicTimer m_fpsTimer; // int m_fpsCounter; - QTime m_repaintTracker; + QElapsedTimer m_repaintTracker; QVector m_paths; QVector m_advances; -- cgit v1.2.3