68class Q_CORE_EXPORT
QFile :
public QFileDevice
73 Q_DECLARE_PRIVATE(QFile)
79 QFILE_MAYBE_EXPLICIT QFile(
const std::filesystem::path &name);
80#elif QT_CONFIG(cxx17_filesystem)
81 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
82 QFILE_MAYBE_EXPLICIT QFile(
const T &name) : QFile(QtPrivate::fromFilesystemPath(name))
88 explicit QFile(QObject *parent);
89 QFile(
const QString &name, QObject *parent);
92 QFile(
const std::filesystem::path &path, QObject *parent);
93#elif QT_CONFIG(cxx17_filesystem)
94 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
95 QFile(
const T &path, QObject *parent) : QFile(QtPrivate::fromFilesystemPath(path), parent)
102 QString fileName()
const override;
103#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
104 std::filesystem::path filesystemFileName()
const
105 {
return QtPrivate::toFilesystemPath(fileName()); }
107 void setFileName(
const QString &name);
109 void setFileName(
const std::filesystem::path &name);
110#elif QT_CONFIG(cxx17_filesystem)
111 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
112 void setFileName(
const T &name)
114 setFileName(QtPrivate::fromFilesystemPath(name));
118#if defined(Q_OS_DARWIN)
120 static inline QByteArray encodeName(
const QString &fileName)
122 return fileName.normalized(QString::NormalizationForm_D).toUtf8();
124 static QString decodeName(
const QByteArray &localFileName)
127 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
129 static inline QString decodeName(
const char *localFileName)
131 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
134 static inline QByteArray encodeName(
const QString &fileName)
136 return fileName.toLocal8Bit();
138 static QString decodeName(
const QByteArray &localFileName)
140 return QString::fromLocal8Bit(localFileName);
142 static inline QString decodeName(
const char *localFileName)
144 return QString::fromLocal8Bit(localFileName);
149 static bool exists(
const QString &fileName);
151 static bool exists(
const std::filesystem::path &fileName);
152#elif QT_CONFIG(cxx17_filesystem)
153 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
154 static bool exists(
const T &fileName)
156 return exists(QtPrivate::fromFilesystemPath(fileName));
160 QString symLinkTarget()
const;
161 static QString symLinkTarget(
const QString &fileName);
163 std::filesystem::path filesystemSymLinkTarget()
const;
164 static std::filesystem::path filesystemSymLinkTarget(
const std::filesystem::path &fileName);
165#elif QT_CONFIG(cxx17_filesystem)
166 std::filesystem::path filesystemSymLinkTarget()
const
168 return QtPrivate::toFilesystemPath(symLinkTarget());
170 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
171 static std::filesystem::path filesystemSymLinkTarget(
const T &fileName)
173 return QtPrivate::toFilesystemPath(symLinkTarget(QtPrivate::fromFilesystemPath(fileName)));
178 static bool remove(
const QString &fileName);
180 static bool remove(
const std::filesystem::path &fileName);
181#elif QT_CONFIG(cxx17_filesystem)
182 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
183 static bool remove(
const T &fileName)
185 return remove(QtPrivate::fromFilesystemPath(fileName));
189 Q_DECL_PURE_FUNCTION
static bool supportsMoveToTrash();
191 static bool moveToTrash(
const QString &fileName, QString *pathInTrash =
nullptr);
193 static bool moveToTrash(
const std::filesystem::path &fileName, QString *pathInTrash =
nullptr);
194#elif QT_CONFIG(cxx17_filesystem)
195 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
196 static bool moveToTrash(
const T &fileName, QString *pathInTrash =
nullptr)
198 return moveToTrash(QtPrivate::fromFilesystemPath(fileName), pathInTrash);
202 bool rename(
const QString &newName);
203 static bool rename(
const QString &oldName,
const QString &newName);
205 bool rename(
const std::filesystem::path &newName);
206 static bool rename(
const std::filesystem::path &oldName,
207 const std::filesystem::path &newName);
208#elif QT_CONFIG(cxx17_filesystem)
209 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
210 bool rename(
const T &newName)
212 return rename(QtPrivate::fromFilesystemPath(newName));
214 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
215 static bool rename(
const T &oldName,
const T &newName)
217 return rename(QtPrivate::fromFilesystemPath(oldName),
218 QtPrivate::fromFilesystemPath(newName));
222 bool link(
const QString &newName);
223 static bool link(
const QString &fileName,
const QString &newName);
225 bool link(
const std::filesystem::path &newName);
226 static bool link(
const std::filesystem::path &fileName,
227 const std::filesystem::path &newName);
228#elif QT_CONFIG(cxx17_filesystem)
229 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
230 bool link(
const T &newName)
232 return link(QtPrivate::fromFilesystemPath(newName));
234 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
235 static bool link(
const T &fileName,
const T &newName)
237 return link(QtPrivate::fromFilesystemPath(fileName),
238 QtPrivate::fromFilesystemPath(newName));
242#if QT_CONFIG(temporaryfile)
243 bool copy(
const QString &newName);
244 static bool copy(
const QString &fileName,
const QString &newName);
247 bool copy(
const std::filesystem::path &newName);
248 static bool copy(
const std::filesystem::path &fileName,
249 const std::filesystem::path &newName);
250#elif QT_CONFIG(cxx17_filesystem) && QT_CONFIG(temporaryfile)
251 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
252 bool copy(
const T &newName)
254 return copy(QtPrivate::fromFilesystemPath(newName));
256 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
257 static bool copy(
const T &fileName,
const T &newName)
259 return copy(QtPrivate::fromFilesystemPath(fileName),
260 QtPrivate::fromFilesystemPath(newName));
264 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags) override;
265 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags, Permissions permissions);
266 QFILE_MAYBE_NODISCARD
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
267 QFILE_MAYBE_NODISCARD
bool open(
int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
269 qint64 size()
const override;
271 bool resize(qint64 sz) override;
272 static bool resize(
const QString &filename, qint64 sz);
274 Permissions permissions()
const override;
275 static Permissions permissions(
const QString &filename);
276 bool setPermissions(Permissions permissionSpec) override;
277 static bool setPermissions(
const QString &filename, Permissions permissionSpec);
279 static Permissions permissions(
const std::filesystem::path &filename);
280 static bool setPermissions(
const std::filesystem::path &filename, Permissions permissionSpec);
281#elif QT_CONFIG(cxx17_filesystem)
282 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
283 static Permissions permissions(
const T &filename)
285 return permissions(QtPrivate::fromFilesystemPath(filename));
287 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
288 static bool setPermissions(
const T &filename, Permissions permissionSpec)
290 return setPermissions(QtPrivate::fromFilesystemPath(filename), permissionSpec);
296 QFile(QFilePrivate &dd);
298 QFile(QFilePrivate &dd, QObject *parent =
nullptr);
302 friend class QTemporaryFile;
303 Q_DISABLE_COPY(QFile)