Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
11
#
if
QT_CONFIG
(
cxx17_filesystem
)
12
#
include
<
filesystem
>
13
#
elif
defined
(
Q_QDOC
)
14
namespace
std {
15
namespace
filesystem {
16
class
path {
17
};
18
};
19
};
20
#
endif
21
22
QT_BEGIN_NAMESPACE
23
24
class
QDateTime;
25
class
QFileDevicePrivate
;
26
27
#
if
QT_CONFIG
(
cxx17_filesystem
)
28
namespace
QtPrivate {
29
inline
QString fromFilesystemPath(
const
std::filesystem::path &path)
30
{
31
// we could use QAnyStringView, but this allows us to statically determine
32
// the correct toString() call
33
using
View = std::conditional_t<
sizeof
(std::filesystem::path::value_type) ==
sizeof
(
char16_t
),
34
QStringView, QUtf8StringView>;
35
return
View(path.native()).toString();
36
}
37
38
inline
std::filesystem::path toFilesystemPath(
const
QString &path)
39
{
40
if
constexpr
(
sizeof
(std::filesystem::path::value_type) ==
sizeof
(
char16_t
))
41
return
std::u16string_view(QStringView(path));
42
else
43
return
path.toStdString();
44
}
45
}
// namespace QtPrivate
46
#
endif
// QT_CONFIG(cxx17_filesystem)
47
48
#
if
!
defined
(
QT_USE_NODISCARD_FILE_OPEN
)
&&
!
defined
(
QT_NO_USE_NODISCARD_FILE_OPEN
)
49
#
if
QT_VERSION
<
QT_VERSION_CHECK
(
6
,
10
,
0
)
50
#
define
QT_NO_USE_NODISCARD_FILE_OPEN
51
#
else
52
#
define
QT_USE_NODISCARD_FILE_OPEN
53
#
endif
54
#
endif
55
56
#
if
defined
(
QT_USE_NODISCARD_FILE_OPEN
)
&&
defined
(
QT_NO_USE_NODISCARD_FILE_OPEN
)
57
#
error
"Inconsistent macro definition for nodiscard QFile::open"
58
#
elif
defined
(
QT_USE_NODISCARD_FILE_OPEN
)
59
#
define
QFILE_MAYBE_NODISCARD
[
[
nodiscard
]
]
60
#
else
/* QT_NO_USE_NODISCARD_FILE_OPEN */
61
#
define
QFILE_MAYBE_NODISCARD
62
#
endif
63
64
class
Q_CORE_EXPORT
QFileDevice
:
public
QIODevice
65
{
66
#
ifndef
QT_NO_QOBJECT
67
Q_OBJECT
68
#
endif
69
Q_DECLARE_PRIVATE(QFileDevice)
70
71
public
:
72
enum
FileError {
73
NoError = 0,
74
ReadError = 1,
75
WriteError = 2,
76
FatalError = 3,
77
ResourceError = 4,
78
OpenError = 5,
79
AbortError = 6,
80
TimeOutError = 7,
81
UnspecifiedError = 8,
82
RemoveError = 9,
83
RenameError = 10,
84
PositionError = 11,
85
ResizeError = 12,
86
PermissionsError = 13,
87
CopyError = 14
88
};
89
90
enum
FileTime {
91
FileAccessTime,
92
FileBirthTime,
93
FileMetadataChangeTime,
94
FileModificationTime
95
};
96
97
enum
Permission {
98
ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
99
ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
100
ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
101
ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
102
};
103
Q_DECLARE_FLAGS(Permissions, Permission)
104
105
enum
FileHandleFlag {
106
AutoCloseHandle = 0x0001,
107
DontCloseHandle = 0
108
};
109
Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
110
111
~QFileDevice();
112
113
FileError error()
const
;
114
void
unsetError();
115
116
void
close() override;
117
118
bool
isSequential()
const
override;
119
120
int
handle()
const
;
121
virtual
QString fileName()
const
;
122
123
qint64 pos()
const
override;
124
bool
seek(qint64 offset) override;
125
bool
atEnd()
const
override;
126
bool
flush();
127
128
qint64 size()
const
override;
129
130
virtual
bool
resize(qint64 sz);
131
virtual
Permissions permissions()
const
;
132
virtual
bool
setPermissions(Permissions permissionSpec);
133
134
enum
MemoryMapFlag {
135
NoOptions = 0,
136
MapPrivateOption = 0x0001
137
};
138
Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag)
139
140
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
141
bool
unmap(uchar *address);
142
143
QDateTime fileTime(QFileDevice::FileTime time)
const
;
144
bool
setFileTime(
const
QDateTime &newDate, QFileDevice::FileTime fileTime);
145
146
protected
:
147
QFileDevice();
148
#
ifdef
QT_NO_QOBJECT
149
QFileDevice(QFileDevicePrivate &dd);
150
#
else
151
explicit
QFileDevice(QObject *parent);
152
QFileDevice(QFileDevicePrivate &dd, QObject *parent =
nullptr
);
153
#
endif
154
155
qint64 readData(
char
*data, qint64 maxlen) override;
156
qint64 writeData(
const
char
*data, qint64 len) override;
157
qint64 readLineData(
char
*data, qint64 maxlen) override;
158
159
private
:
160
Q_DISABLE_COPY(QFileDevice)
161
};
162
163
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
164
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags)
165
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags)
166
167
QT_END_NAMESPACE
168
169
#
endif
// QFILEDEVICE_H
QFileDevicePrivate
Definition
qfiledevice_p.h:43
QFileDevicePrivate::putCharHelper
bool putCharHelper(char c) override
Definition
qfiledevice.cpp:507
QFileDevicePrivate::lastWasWrite
bool lastWasWrite
Definition
qfiledevice_p.h:70
QFileDevicePrivate::setError
void setError(QFileDevice::FileError err, QString errorString)
Definition
qfiledevice.cpp:58
QFileDevicePrivate::engine
virtual QAbstractFileEngine * engine() const
Definition
qfiledevice.cpp:29
QFileDevicePrivate::setError
void setError(QFileDevice::FileError err)
Definition
qfiledevice.cpp:52
QFileDevicePrivate::setPermissions
virtual bool setPermissions(QFileDevice::Permissions perms)
Definition
qfiledevice.cpp:42
QFileDevicePrivate::~QFileDevicePrivate
~QFileDevicePrivate()
QFileDevice
\inmodule QtCore
Definition
qfiledevice.h:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QFILE_WRITEBUFFER_SIZE
#define QFILE_WRITEBUFFER_SIZE
Definition
qfiledevice.cpp:17
QT_USE_NODISCARD_FILE_OPEN
#define QT_USE_NODISCARD_FILE_OPEN
Definition
qfiledevice.h:52
qtbase
src
corelib
io
qfiledevice.h
Generated on
for Qt by
1.18.0