95class Q_CORE_EXPORT
QFile :
public QFileDevice
100 Q_DECLARE_PRIVATE(QFile)
106 QFILE_MAYBE_EXPLICIT QFile(
const std::filesystem::path &name);
107#elif QT_CONFIG(cxx17_filesystem)
108 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
109 QFILE_MAYBE_EXPLICIT QFile(
const T &name) : QFile(QtPrivate::fromFilesystemPath(name))
115 explicit QFile(QObject *parent);
116 QFile(
const QString &name, QObject *parent);
119 QFile(
const std::filesystem::path &path, QObject *parent);
120#elif QT_CONFIG(cxx17_filesystem)
121 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
122 QFile(
const T &path, QObject *parent) : QFile(QtPrivate::fromFilesystemPath(path), parent)
129 QString fileName()
const override;
130#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
131 std::filesystem::path filesystemFileName()
const
132 {
return QtPrivate::toFilesystemPath(fileName()); }
134 void setFileName(
const QString &name);
136 void setFileName(
const std::filesystem::path &name);
137#elif QT_CONFIG(cxx17_filesystem)
138 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
139 void setFileName(
const T &name)
141 setFileName(QtPrivate::fromFilesystemPath(name));
145#if defined(Q_OS_DARWIN)
147 static inline QByteArray encodeName(
const QString &fileName)
149 return fileName.normalized(QString::NormalizationForm_D).toUtf8();
151 static QString decodeName(
const QByteArray &localFileName)
154 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
156 static inline QString decodeName(
const char *localFileName)
158 return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C);
161 static inline QByteArray encodeName(
const QString &fileName)
163 return fileName.toLocal8Bit();
165 static QString decodeName(
const QByteArray &localFileName)
167 return QString::fromLocal8Bit(localFileName);
169 static inline QString decodeName(
const char *localFileName)
171 return QString::fromLocal8Bit(localFileName);
176 static bool exists(
const QString &fileName);
178 static bool exists(
const std::filesystem::path &fileName);
179#elif QT_CONFIG(cxx17_filesystem)
180 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
181 static bool exists(
const T &fileName)
183 return exists(QtPrivate::fromFilesystemPath(fileName));
187 QString symLinkTarget()
const;
188 static QString symLinkTarget(
const QString &fileName);
190 std::filesystem::path filesystemSymLinkTarget()
const;
191 static std::filesystem::path filesystemSymLinkTarget(
const std::filesystem::path &fileName);
192#elif QT_CONFIG(cxx17_filesystem)
193 std::filesystem::path filesystemSymLinkTarget()
const
195 return QtPrivate::toFilesystemPath(symLinkTarget());
197 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
198 static std::filesystem::path filesystemSymLinkTarget(
const T &fileName)
200 return QtPrivate::toFilesystemPath(symLinkTarget(QtPrivate::fromFilesystemPath(fileName)));
205 static bool remove(
const QString &fileName);
207 static bool remove(
const std::filesystem::path &fileName);
208#elif QT_CONFIG(cxx17_filesystem)
209 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
210 static bool remove(
const T &fileName)
212 return remove(QtPrivate::fromFilesystemPath(fileName));
216 Q_DECL_PURE_FUNCTION
static bool supportsMoveToTrash();
218 static bool moveToTrash(
const QString &fileName, QString *pathInTrash =
nullptr);
220 static bool moveToTrash(
const std::filesystem::path &fileName, QString *pathInTrash =
nullptr);
221#elif QT_CONFIG(cxx17_filesystem)
222 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
223 static bool moveToTrash(
const T &fileName, QString *pathInTrash =
nullptr)
225 return moveToTrash(QtPrivate::fromFilesystemPath(fileName), pathInTrash);
229 bool rename(
const QString &newName);
230 static bool rename(
const QString &oldName,
const QString &newName);
232 bool rename(
const std::filesystem::path &newName);
233 static bool rename(
const std::filesystem::path &oldName,
234 const std::filesystem::path &newName);
235#elif QT_CONFIG(cxx17_filesystem)
236 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
237 bool rename(
const T &newName)
239 return rename(QtPrivate::fromFilesystemPath(newName));
241 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
242 static bool rename(
const T &oldName,
const T &newName)
244 return rename(QtPrivate::fromFilesystemPath(oldName),
245 QtPrivate::fromFilesystemPath(newName));
249 bool link(
const QString &newName);
250 static bool link(
const QString &fileName,
const QString &newName);
252 bool link(
const std::filesystem::path &newName);
253 static bool link(
const std::filesystem::path &fileName,
254 const std::filesystem::path &newName);
255#elif QT_CONFIG(cxx17_filesystem)
256 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
257 bool link(
const T &newName)
259 return link(QtPrivate::fromFilesystemPath(newName));
261 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
262 static bool link(
const T &fileName,
const T &newName)
264 return link(QtPrivate::fromFilesystemPath(fileName),
265 QtPrivate::fromFilesystemPath(newName));
269#if QT_CONFIG(temporaryfile)
270 bool copy(
const QString &newName);
271 static bool copy(
const QString &fileName,
const QString &newName);
274 bool copy(
const std::filesystem::path &newName);
275 static bool copy(
const std::filesystem::path &fileName,
276 const std::filesystem::path &newName);
277#elif QT_CONFIG(cxx17_filesystem) && QT_CONFIG(temporaryfile)
278 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
279 bool copy(
const T &newName)
281 return copy(QtPrivate::fromFilesystemPath(newName));
283 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
284 static bool copy(
const T &fileName,
const T &newName)
286 return copy(QtPrivate::fromFilesystemPath(fileName),
287 QtPrivate::fromFilesystemPath(newName));
291 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags) override;
292 QFILE_MAYBE_NODISCARD
bool open(OpenMode flags, Permissions permissions);
293 QFILE_MAYBE_NODISCARD
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
294 QFILE_MAYBE_NODISCARD
bool open(
int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
296 qint64 size()
const override;
298 bool resize(qint64 sz) override;
299 static bool resize(
const QString &filename, qint64 sz);
301 Permissions permissions()
const override;
302 static Permissions permissions(
const QString &filename);
303 bool setPermissions(Permissions permissionSpec) override;
304 static bool setPermissions(
const QString &filename, Permissions permissionSpec);
306 static Permissions permissions(
const std::filesystem::path &filename);
307 static bool setPermissions(
const std::filesystem::path &filename, Permissions permissionSpec);
308#elif QT_CONFIG(cxx17_filesystem)
309 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
310 static Permissions permissions(
const T &filename)
312 return permissions(QtPrivate::fromFilesystemPath(filename));
314 template<
typename T, QtPrivate::ForceFilesystemPath<T> = 0>
315 static bool setPermissions(
const T &filename, Permissions permissionSpec)
317 return setPermissions(QtPrivate::fromFilesystemPath(filename), permissionSpec);
323 QFile(QFilePrivate &dd);
325 QFile(QFilePrivate &dd, QObject *parent =
nullptr);
329 friend class QTemporaryFile;
330 Q_DISABLE_COPY(QFile)