5#ifndef QTEMPORARYFILE_H
6#define QTEMPORARYFILE_H
8#include <QtCore/qiodevice.h>
9#include <QtCore/qfile.h>
12#error qtemporaryfile.h must be included before any header file that defines open
18#if QT_CONFIG(temporaryfile)
20class QTemporaryFilePrivate;
21class QLockFilePrivate;
23class Q_CORE_EXPORT QTemporaryFile :
public QFile
28 Q_DECLARE_PRIVATE(QTemporaryFile)
32 explicit QTemporaryFile(
const QString &templateName);
34 explicit QTemporaryFile(QObject *parent);
35 QTemporaryFile(
const QString &templateName, QObject *parent);
37# if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
39 explicit QTemporaryFile(
const std::filesystem::path &templateName, QObject *parent =
nullptr)
40 : QTemporaryFile(QtPrivate::fromFilesystemPath(templateName), parent)
48 bool autoRemove()
const;
49 void setAutoRemove(
bool b);
52 QFILE_MAYBE_NODISCARD
bool open() {
return open(QIODevice::ReadWrite); }
54 QString fileName()
const override;
55 QString fileTemplate()
const;
56 void setFileTemplate(
const QString &name);
57#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
59 void setFileTemplate(
const std::filesystem::path &name)
61 return setFileTemplate(QtPrivate::fromFilesystemPath(name));
66 bool rename(
const QString &newName);
67 bool renameOverwrite(
const QString &newName);
69#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
71 bool rename(
const std::filesystem::path &newName)
73 return rename(QtPrivate::fromFilesystemPath(newName));
76 bool renameOverwrite(
const std::filesystem::path &newName)
77 {
return renameOverwrite(QtPrivate::fromFilesystemPath(newName)); }
80 inline static QTemporaryFile *createNativeFile(
const QString &fileName)
81 { QFile file(fileName);
return createNativeFile(file); }
82 static QTemporaryFile *createNativeFile(QFile &file);
84#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
86 static QTemporaryFile *createNativeFile(
const std::filesystem::path &fileName)
89 return createNativeFile(file);
94 bool open(OpenMode flags) override;
98 friend class QLockFilePrivate;
99 Q_DISABLE_COPY(QTemporaryFile)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
static Q_DECL_COLD_FUNCTION bool file_already_open(QFile &file, const char *where=nullptr)
#define QFILEINFO_MAYBE_EXPLICIT
QList< QFileInfo > QFileInfoList