summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShantanu Tushar <shantanu.tushar@kdab.com>2020-10-16 17:09:44 +0200
committerShantanu Tushar <shantanu.tushar@kdab.com>2020-10-18 20:16:38 +0200
commit927cd268aac8e1a97a127f63b9dd83e831c8b642 (patch)
tree1f146319bf12d4ca462e953c82e79ea27d0d45b7
parent9402a351dd1f37d595660010c7a55a7c8fb5e668 (diff)
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>
-rw-r--r--src/corelib/io/qlockfile.cpp8
-rw-r--r--src/corelib/io/qlockfile.h2
-rw-r--r--tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp
index aa84ce6bc1..ba2dc28339 100644
--- a/src/corelib/io/qlockfile.cpp
+++ b/src/corelib/io/qlockfile.cpp
@@ -151,6 +151,14 @@ QLockFile::~QLockFile()
}
/*!
+ * 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.
The default value is 30000, i.e. 30 seconds.
diff --git a/src/corelib/io/qlockfile.h b/src/corelib/io/qlockfile.h
index 8b94900901..ba955241b6 100644
--- a/src/corelib/io/qlockfile.h
+++ b/src/corelib/io/qlockfile.h
@@ -53,6 +53,8 @@ public:
QLockFile(const QString &fileName);
~QLockFile();
+ QString fileName() const;
+
bool lock();
bool tryLock(int timeout = 0);
void unlock();
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
index 708716e7e2..54d2182e5c 100644
--- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
+++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
@@ -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));