Qt: Flesh out VFileDevice more, to avoid leak
Vicki Pfau vi@endrift.com
Sat, 30 Jan 2021 16:01:06 -0800
2 files changed,
13 insertions(+),
0 deletions(-)
M
src/platform/qt/VFileDevice.cpp
→
src/platform/qt/VFileDevice.cpp
@@ -91,6 +91,10 @@ setOpenMode(mode);
} } +VFileDevice::~VFileDevice() { + close(); +} + void VFileDevice::close() { if (!m_vf) { return;@@ -115,6 +119,13 @@ close();
m_vf = vf; setOpenMode(QIODevice::ReadWrite); return *this; +} + +VFile* VFileDevice::take() { + VFile* vf = m_vf; + m_vf = nullptr; + QIODevice::close(); + return vf; } qint64 VFileDevice::readData(char* data, qint64 maxSize) {
M
src/platform/qt/VFileDevice.h
→
src/platform/qt/VFileDevice.h
@@ -20,6 +20,7 @@
public: VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr); VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr); + virtual ~VFileDevice(); virtual void close() override; virtual bool seek(qint64 pos) override;@@ -29,6 +30,7 @@ bool resize(qint64 sz);
VFileDevice& operator=(VFile*); operator VFile*() { return m_vf; } + VFile* take(); static VFile* wrap(QIODevice*, QIODevice::OpenMode); static VFile* wrap(QFileDevice*, QIODevice::OpenMode);