Make QElapsedTimer optional in QLockFile.

This restores compatibility with Qt 4.6.
This commit is contained in:
Felix Geyer 2015-07-16 21:52:08 +02:00
parent 826cd472c8
commit 8325b20d36

View File

@ -33,8 +33,11 @@
#include "qlockfile.h" #include "qlockfile.h"
#include "qlockfile_p.h" #include "qlockfile_p.h"
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
#include <QElapsedTimer> # include <QElapsedTimer>
#else
# include <QTime>
#endif
#include <QDateTime> #include <QDateTime>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -199,7 +202,11 @@ bool QLockFile::lock()
bool QLockFile::tryLock(int timeout) bool QLockFile::tryLock(int timeout)
{ {
Q_D(QLockFile); Q_D(QLockFile);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
QElapsedTimer timer; QElapsedTimer timer;
#else
QTime timer;
#endif
if (timeout > 0) if (timeout > 0)
timer.start(); timer.start();
int sleepTime = 100; int sleepTime = 100;
@ -224,7 +231,7 @@ bool QLockFile::tryLock(int timeout)
} }
break; break;
} }
if (timeout == 0 || (timeout > 0 && timer.hasExpired(timeout))) if (timeout == 0 || (timeout > 0 && (timer.elapsed() > timeout)))
return false; return false;
QLockFileThread::msleep(sleepTime); QLockFileThread::msleep(sleepTime);
if (sleepTime < 5 * 1000) if (sleepTime < 5 * 1000)