Qt: Add VFileDevice from filename API

This commit is contained in:
Vicki Pfau 2020-08-25 20:21:58 -07:00
parent fcda3df24d
commit 6c805acab6
2 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,23 @@ VFileDevice::VFileDevice(VFile* vf, QObject* parent)
}
}
VFileDevice::VFileDevice(const QString& filename, QIODevice::OpenMode mode, QObject* parent)
: QIODevice(parent)
{
int posixMode = 0;
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite) {
posixMode = O_RDWR;
} else if (mode & QIODevice::ReadOnly) {
posixMode = O_RDONLY;
} else if (mode & QIODevice::WriteOnly) {
posixMode = O_WRONLY;
}
m_vf = open(filename, posixMode);
if (m_vf) {
setOpenMode(mode);
}
}
void VFileDevice::close() {
if (!m_vf) {
return;

View File

@ -17,6 +17,7 @@ Q_OBJECT
public:
VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr);
VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr);
virtual void close() override;
virtual bool seek(qint64 pos) override;