Add function to access QLockFile's file name

This is useful in cases like error handling when you need to print the
name of the lock file.

Change-Id: Ife4901ed53ae81d19e68cce7f1c173ef3745d56f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Shantanu Tushar 2020-10-16 17:09:44 +02:00
parent 9402a351dd
commit 927cd268aa
3 changed files with 11 additions and 0 deletions

View File

@ -150,6 +150,14 @@ QLockFile::~QLockFile()
unlock();
}
/*!
* Returns the file name of the lock file
*/
QString QLockFile::fileName() const
{
return d_ptr->fileName;
}
/*!
Sets \a staleLockTime to be the time in milliseconds after which
a lock file is considered stale.

View File

@ -53,6 +53,8 @@ public:
QLockFile(const QString &fileName);
~QLockFile();
QString fileName() const;
bool lock();
bool tryLock(int timeout = 0);
void unlock();

View File

@ -96,6 +96,7 @@ void tst_QLockFile::lockUnlock()
const QString fileName = dir.path() + "/lock1";
QVERIFY(!QFile(fileName).exists());
QLockFile lockFile(fileName);
QCOMPARE(lockFile.fileName(), fileName);
QVERIFY(lockFile.lock());
QVERIFY(lockFile.isLocked());
QCOMPARE(int(lockFile.error()), int(QLockFile::NoError));