94class Q_CORE_EXPORT
QFile :
public QFileDevice
99 Q_DECLARE_PRIVATE(QFile)
105 QFILE_MAYBE_EXPLICIT QFile(
const std::filesystem::path &name);
106#elif QT_CONFIG(cxx17_filesystem)
107 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
108 QFILE_MAYBE_EXPLICIT QFile(
const T &name) : QFile(QtPrivate::fromFilesystemPath(name))
114 explicit QFile(QObject *parent);
115 QFile(
const QString &name, QObject *parent);
118 QFile(
const std::filesystem::path &path, QObject *parent);
119#elif QT_CONFIG(cxx17_filesystem)
120 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
121 QFile(
const T &path, QObject *parent) : QFile(QtPrivate::fromFilesystemPath(path), parent)
128 QString fileName()
const override;
129#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
130 std::filesystem::path filesystemFileName()
const
131 {
return QtPrivate::toFilesystemPath(fileName()); }
133 void setFileName(
const QString &name);
135 void setFileName(
const std::filesystem::path &name);
136#elif QT_CONFIG(cxx17_filesystem)
137 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
138 void setFileName(
const T &name)
140 setFileName(QtPrivate::fromFilesystemPath(name));
144#if defined(Q_OS_DARWIN)
146 static inline QByteArray encodeName(
const QString &fileName)
148 return fileName.normalized(QString::NormalizationForm_D).toUtf8();
150 static QString decodeName(
const QByteArray &localFileName)
153 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
155 static inline QString decodeName(
const char *localFileName)
157 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
160 static inline QByteArray encodeName(
const QString &fileName)
162 return fileName.toLocal8Bit();
164 static QString decodeName(
const QByteArray &localFileName)
166 return QString::fromLocal8Bit(localFileName);
168 static inline QString decodeName(
const char *localFileName)
170 return QString::fromLocal8Bit(localFileName);
175 static bool exists(
const QString &fileName);
177 static bool exists(
const std::filesystem::path &fileName);
178#elif QT_CONFIG(cxx17_filesystem)
179 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
180 static bool exists(
const T &fileName)
182 return exists(QtPrivate::fromFilesystemPath(fileName));
186 QString symLinkTarget()
const;
187 static QString symLinkTarget(
const QString &fileName);
189 std::filesystem::path filesystemSymLinkTarget()
const;
190 static std::filesystem::path filesystemSymLinkTarget(
const std::filesystem::path &fileName);
191#elif QT_CONFIG(cxx17_filesystem)
192 std::filesystem::path filesystemSymLinkTarget()
const
194 return QtPrivate::toFilesystemPath(symLinkTarget());
196 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
197 static std::filesystem::path filesystemSymLinkTarget(
const T &fileName)
199 return QtPrivate::toFilesystemPath(symLinkTarget(QtPrivate::fromFilesystemPath(fileName)));
204 static bool remove(
const QString &fileName);
206 static bool remove(
const std::filesystem::path &fileName);
207#elif QT_CONFIG(cxx17_filesystem)
208 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
209 static bool remove(
const T &fileName)
211 return remove(QtPrivate::fromFilesystemPath(fileName));
215 static bool supportsMoveToTrash() Q_DECL_PURE_FUNCTION;
217 static bool moveToTrash(
const QString &fileName, QString *pathInTrash =
nullptr);
219 static bool moveToTrash(
const std::filesystem::path &fileName, QString *pathInTrash =
nullptr);
220#elif QT_CONFIG(cxx17_filesystem)
221 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
222 static bool moveToTrash(
const T &fileName, QString *pathInTrash =
nullptr)
224 return moveToTrash(QtPrivate::fromFilesystemPath(fileName), pathInTrash);
228 bool rename(
const QString &newName);
229 static bool rename(
const QString &oldName,
const QString &newName);
231 bool rename(
const std::filesystem::path &newName);
232 static bool rename(
const std::filesystem::path &oldName,
233 const std::filesystem::path &newName);
234#elif QT_CONFIG(cxx17_filesystem)
235 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
236 bool rename(
const T &newName)
238 return rename(QtPrivate::fromFilesystemPath(newName));
240 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
241 static bool rename(
const T &oldName,
const T &newName)
243 return rename(QtPrivate::fromFilesystemPath(oldName),
244 QtPrivate::fromFilesystemPath(newName));
248 bool link(
const QString &newName);
249 static bool link(
const QString &fileName,
const QString &newName);
251 bool link(
const std::filesystem::path &newName);
252 static bool link(
const std::filesystem::path &fileName,
253 const std::filesystem::path &newName);
254#elif QT_CONFIG(cxx17_filesystem)
255 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
256 bool link(
const T &newName)
258 return link(QtPrivate::fromFilesystemPath(newName));
260 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
261 static bool link(
const T &fileName,
const T &newName)
263 return link(QtPrivate::fromFilesystemPath(fileName),
264 QtPrivate::fromFilesystemPath(newName));
268#if QT_CONFIG(temporaryfile)
269 bool copy(
const QString &newName);
270 static bool copy(
const QString &fileName,
const QString &newName);
273 bool copy(
const std::filesystem::path &newName);
274 static bool copy(
const std::filesystem::path &fileName,
275 const std::filesystem::path &newName);
276#elif QT_CONFIG(cxx17_filesystem) && QT_CONFIG(temporaryfile)
277 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
278 bool copy(
const T &newName)
280 return copy(QtPrivate::fromFilesystemPath(newName));
282 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
283 static bool copy(
const T &fileName,
const T &newName)
285 return copy(QtPrivate::fromFilesystemPath(fileName),
286 QtPrivate::fromFilesystemPath(newName));
290 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags) override;
291 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags, Permissions permissions);
292 QFILE_MAYBE_NODISCARD
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
293 QFILE_MAYBE_NODISCARD
bool open(
int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
295 qint64 size()
const override;
297 bool resize(qint64 sz) override;
298 static bool resize(
const QString &filename, qint64 sz);
300 Permissions permissions()
const override;
301 static Permissions permissions(
const QString &filename);
302 bool setPermissions(Permissions permissionSpec) override;
303 static bool setPermissions(
const QString &filename, Permissions permissionSpec);
305 static Permissions permissions(
const std::filesystem::path &filename);
306 static bool setPermissions(
const std::filesystem::path &filename, Permissions permissionSpec);
307#elif QT_CONFIG(cxx17_filesystem)
308 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
309 static Permissions permissions(
const T &filename)
311 return permissions(QtPrivate::fromFilesystemPath(filename));
313 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
314 static bool setPermissions(
const T &filename, Permissions permissionSpec)
316 return setPermissions(QtPrivate::fromFilesystemPath(filename), permissionSpec);
322 QFile(QFilePrivate &dd);
324 QFile(QFilePrivate &dd, QObject *parent =
nullptr);
328 friend class QTemporaryFile;
329 Q_DISABLE_COPY(QFile)