]> git.lyx.org Git - features.git/commitdiff
Fix Qt deprecation warns for QTime
authorScott Kostyshak <skostysh@lyx.org>
Mon, 16 Mar 2020 00:32:16 +0000 (20:32 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Mon, 16 Mar 2020 02:47:08 +0000 (22:47 -0400)
This commit fixes a couple of warnings from Qt 5.14 like the
following one:

  error: ‘int QTime::restart()’ is deprecated: Use QElapsedTimer instead [-Werror=deprecated-declarations]

This commit changes two uses of QTime to QElapsedTimer, one used
only when the "files" debug flag is set, and the other for timing
whether a script (e.g., knitr) takes longer than a certain amount of
time to run.

QElapsedTimer is superior for these two use cases in that it uses a
monotonic clock if possible, and is thus more robust to certain
changes (e.g., daylight savings changes) [1]. Similarly, the commit
in Qt Base that makes this deprecation [2] mentions the following in
the commit message:

  QElapsedTimer does the job better and without the DST kludges.

Note that QElapsedTimer class was introduced in Qt 4.7, so no
conditioning on Qt version is necessary.

Not all methods of QTime are deprecated and we still use some of
the non-deprecated methods in our code (e.g., to get the current
wall clock time in GuiProgress::currentTime()).

[1] https://doc.qt.io/qt-5/qelapsedtimer.html
[2] https://code.qt.io/cgit/qt/qtbase.git/commit/?id=ed99a591a83a399458f12341d0a1c0b3152f247a

src/support/FileName.cpp
src/support/Systemcall.cpp

index 505b485d7f1f7fe2871e54ffe9ebc1b1c57dd45b..179fef46ee92e2b419fd8f18e33d74b162a3472c 100644 (file)
@@ -28,7 +28,7 @@
 #include <QFileInfo>
 #include <QList>
 #include <QTemporaryFile>
-#include <QTime>
+#include <QElapsedTimer>
 
 #ifdef _WIN32
 #include <QThread>
@@ -563,7 +563,7 @@ unsigned long FileName::checksum() const
        }
 
        // This is used in the debug output at the end of the method.
-       static QTime t;
+       static QElapsedTimer t;
        if (lyxerr.debugging(Debug::FILES))
                t.restart();
 
index f5b6c27a506a3b2af3a0bfac841c90972ea85269..d0ff9ae993f1111bad555976db32d16d992f3d24 100644 (file)
@@ -29,7 +29,7 @@
 #include <iostream>
 
 #include <QProcess>
-#include <QTime>
+#include <QElapsedTimer>
 #include <QThread>
 #include <QCoreApplication>
 #include <QDebug>
@@ -467,7 +467,7 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
        }
 
        // process events while waiting with timeout
-       QTime timer;
+       QElapsedTimer timer;
        timer.start();
        while (state == waitwhile && state != Error && !timedout) {
                // check for cancellation of background process