Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfiledevice.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QFILEDEVICE_H
6#define QFILEDEVICE_H
7
8#include <QtCore/qiodevice.h>
9#include <QtCore/qstring.h>
10
11QT_BEGIN_NAMESPACE
12
13class QDateTime;
15
16#if !defined(QT_USE_NODISCARD_FILE_OPEN) && !defined(QT_NO_USE_NODISCARD_FILE_OPEN)
17# if QT_VERSION < QT_VERSION_CHECK(6, 10, 0)
18# define QT_NO_USE_NODISCARD_FILE_OPEN
19# else
20# define QT_USE_NODISCARD_FILE_OPEN
21# endif
22#endif
23
24#if defined(QT_USE_NODISCARD_FILE_OPEN) && defined(QT_NO_USE_NODISCARD_FILE_OPEN)
25#error "Inconsistent macro definition for nodiscard QFile::open"
26#elif defined(QT_USE_NODISCARD_FILE_OPEN)
27#define QFILE_MAYBE_NODISCARD [[nodiscard]]
28#else /* QT_NO_USE_NODISCARD_FILE_OPEN */
29#define QFILE_MAYBE_NODISCARD
30#endif
31
32class Q_CORE_EXPORT QFileDevice : public QIODevice
33{
34#ifndef QT_NO_QOBJECT
35 Q_OBJECT
36#endif
37 Q_DECLARE_PRIVATE(QFileDevice)
38
39public:
40 enum FileError {
41 NoError = 0,
42 ReadError = 1,
43 WriteError = 2,
44 FatalError = 3,
45 ResourceError = 4,
46 OpenError = 5,
47 AbortError = 6,
48 TimeOutError = 7,
49 UnspecifiedError = 8,
50 RemoveError = 9,
51 RenameError = 10,
52 PositionError = 11,
53 ResizeError = 12,
54 PermissionsError = 13,
55 CopyError = 14
56 };
57
58 enum FileTime {
59 FileAccessTime,
60 FileBirthTime,
61 FileMetadataChangeTime,
62 FileModificationTime
63 };
64
65 enum Permission {
66 ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
67 ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
68 ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
69 ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
70 };
71 Q_DECLARE_FLAGS(Permissions, Permission)
72
73 enum FileHandleFlag {
74 AutoCloseHandle = 0x0001,
75 DontCloseHandle = 0
76 };
77 Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
78
79 ~QFileDevice();
80
81 FileError error() const;
82 void unsetError();
83
84 void close() override;
85
86 bool isSequential() const override;
87
88 int handle() const;
89 virtual QString fileName() const;
90
91 qint64 pos() const override;
92 bool seek(qint64 offset) override;
93 bool atEnd() const override;
94 bool flush();
95
96 qint64 size() const override;
97
98 virtual bool resize(qint64 sz);
99 virtual Permissions permissions() const;
100 virtual bool setPermissions(Permissions permissionSpec);
101
102 enum MemoryMapFlag {
103 NoOptions = 0,
104 MapPrivateOption = 0x0001
105 };
106 Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag)
107
108 uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
109 bool unmap(uchar *address);
110
111 QDateTime fileTime(QFileDevice::FileTime time) const;
112 bool setFileTime(const QDateTime &newDate, QFileDevice::FileTime fileTime);
113
114protected:
115 QFileDevice();
116#ifdef QT_NO_QOBJECT
117 QFileDevice(QFileDevicePrivate &dd);
118#else
119 explicit QFileDevice(QObject *parent);
120 QFileDevice(QFileDevicePrivate &dd, QObject *parent = nullptr);
121#endif
122
123 qint64 readData(char *data, qint64 maxlen) override;
124 qint64 writeData(const char *data, qint64 len) override;
125 qint64 readLineData(char *data, qint64 maxlen) override;
126
127private:
128 Q_DISABLE_COPY(QFileDevice)
129};
130
131Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
132Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags)
133Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags)
134
135QT_END_NAMESPACE
136
137#endif // QFILEDEVICE_H
void setError(QFileDevice::FileError err, int errNum)
bool putCharHelper(char c) override
virtual QAbstractFileEngine * engine() const
void setError(QFileDevice::FileError err)
void setError(QFileDevice::FileError err, const QString &errorString)
\inmodule QtCore
Definition qfiledevice.h:33
#define QFILE_WRITEBUFFER_SIZE
#define QT_USE_NODISCARD_FILE_OPEN
Definition qfiledevice.h:20